<div id="tabgetinvoicemesin_bc23" style="height:440px">
	<ul>
		<li><a id="idtabgetinvoicemesin_bc23_fileuploaded" href="#divtabgetinvoicemesin_bc23_fileuploaded">File Invoice Uploaded</a></li>
		<li><a id="idtabgetinvoicemesin_bc23_viewdata" href="#divtabgetinvoicemesin_bc23_viewdata">Proses & View Data</a></li>
		<li><a id="idtabinvoicekurir_bc23_form" href="#divtabinvoicekurir_bc23_form">Form Kurir</a></li>
	</ul>
	<div id="divtabgetinvoicemesin_bc23_fileuploaded">
		<table id="tblgetinvoicemesinuploaded_bc23"></table> <div id="ptblgetinvoicemesinuploaded_bc23"></div>   	
	</div>
	<div id="divtabgetinvoicemesin_bc23_viewdata">
		<button id="btnviewinvoicemesinproses_bc23" >Proses File Invoice</button>
		<button id="btnviewdetilinvoicemesinprosesbc23_bc23" >Detil Invoice/Update Data</button>
		<button id="btnupdateinvoicemesinproses_bc23" >Update TGL Invoice</button>
		<button id="btnprosesinvoicemesinproses_bc23" >PROSES BC23</button>
		<div style="height:5px" />
		<table id="tbl_proses_inv_mesinsparepart_hdr"></table> <div id="ptbl_proses_inv_mesinsparepart_hdr"></div> 
	</div>
	<div id="divtabinvoicekurir_bc23_form">
		<button id="btnproses_kurir_bc23" >Load Data Kurir</button>
	</div>
</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#tabgetinvoicemesin_bc23").tabs();
		
		$("#btnviewinvoicemesinproses_bc23").button().click(function(){
			var id = jQuery("#tblgetinvoicemesinuploaded_bc23").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblgetinvoicemesinuploaded_bc23").jqGrid('getRowData',id);
				
			} else {
				$("#tabgetinvoicemesin_bc23").tabs("select", 0);
				alert("Please Select Row Invoice");
				return false;
			};	
			
			if( ret.status_upload != 'SUKSES') {
			
			    alert("Data tidak dapat di proses..Lihat status");
				$("#tabgetinvoicemesin_bc23").tabs("select", 0);
				return false;
			};	
			
			var form_data;
			form_data = {
				id_inv_mesin:ret.id_invoice_uploadmpk
			
			};
			$("#dlg_proses_inv_mesinsparepart").dialog( "destroy" );
			$(".dlg_proses_inv_mesinsparepart_cl").remove();
			$(".dlg_proses_inv_mesinsparepart_cl").html('');
			$("body").append('<div id="dlg_proses_inv_mesinsparepart" title="Warning" class="dlg_proses_inv_mesinsparepart_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename +'..?</p><br />Mohon diperiksa kembali datanya.</div>');
			$("#dlg_proses_inv_mesinsparepart").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23/proses_inv_mesinsparepart'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_proses_inv_mesinsparepart").dialog("close");
								$('#dlg_proses_inv_mesinsparepart').dialog("destroy"); 
								$(".dlg_proses_inv_mesinsparepart_cl").remove(); 
								$(".dlg_proses_inv_mesinsparepart_cl").html('');
								jQuery("#tbl_proses_inv_mesinsparepart_hdr").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_proses_inv_mesinsparepart").dialog("close");
								$('#dlg_proses_inv_mesinsparepart').dialog("destroy"); 
								$(".dlg_proses_inv_mesinsparepart_cl").remove(); 
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_proses_inv_mesinsparepart" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_proses_inv_mesinsparepart').dialog("destroy"); 
					$(".dlg_proses_inv_mesinsparepart_cl").remove(); 
					//$("body").append('<div id="dlg_proses_inv_mesinsparepart" title="Warning" class="dlg_proses_inv_mesinsparepart_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename  +'..?</p><br />Mohon diperiksa kembali datanya.</div>.</div>');     
					
				},
				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_") {
                // in case of searching toolbar
					setTimeout(function(){
					jQuery("#tbluploadinvoice").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		
		jQuery("#tblgetinvoicemesinuploaded_bc23").jqGrid({
			url:'<?php echo base_url().'invoice/ct_invoice_mpk/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by','Update Date', 'Update By'],
			colModel:[
				{name:'id_invoice_uploadmpk',index:'id_invoice_uploadmpk', width:60, hidden:true},
				{name:'filename',index:'filename', width:160},
				{name:'date_upload',index:'date_upload', width:166,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'status_upload',index:'status_upload', width:106},
				{name:'tipe',index:'tipe', width:106},
				{name:'create_date',index:'create_date', width:166, hidden:false,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'create_by',index:'create_by', width:106, hidden:false},
				{name:'update_date',index:'update_date', width:166, hidden:false,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'update_by',index:'update_by', width:106, hidden:false}
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblgetinvoicemesinuploaded_bc23',
			sortname: 'id_invoice_uploadmpk',
			viewrecords: true,
			sortorder: "desc",
			width: 850,
			height:280,
			jsonReader: { repeatitems : false },
			caption:"List of Files Upload",
			rownumbers: true,
			shrinkToFit: false,
			
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tblgetinvoicemesinuploaded_bc23").getDataIDs(); 
				var rowData = $("#tblgetinvoicemesinuploaded_bc23").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblgetinvoicemesinuploaded_bc23'));
				   
					switch (rowData[i].status_upload) {
						
						case 'cancel':
						   trElement.css({"color":"red"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
		
		jQuery("#tblgetinvoicemesinuploaded_bc23").jqGrid('navGrid','#ptblgetinvoicemesinuploaded_bc23',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblgetinvoicemesinuploaded_bc23").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		function myformatter ( cellvalue, options, rowObject )
		{
			if (cellvalue == "New")
				 return "<font color='red'>" + cellvalue + '</font>';//or use classes
			else
				 return "<font color='red'>" + cellvalue + '</font>';//or use classes
		}
		
		var $grid = $("#tbl_proses_inv_mesinsparepart_hdr");
		$grid.jqGrid({
		url:'<?php echo base_url().'exim/ct_bc23/loaddata_proses_inv_mesinsparepart_hdr'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['invoice no'
			  ,'invoice date'
			  ,'No BL'
			  ,'Tgl BL'
			  ,'kode supplier'
			  ,'order no'
			  ,'order date'
			  ,'status data'
				],
			colModel:[
				{name:'invoice_no',index:'invoice_no', width:160},
				{name:'invoice_date',index:'invoice_date', width:160,
					editable:true, 
					edittype:'text', 
					editoptions: { dataInit: 
						function(el){$(el).datepicker({
								changeYear: true,
								showButtonPanel: true,
								changeMonth: true, 
								dateFormat:'yy-mm-dd',
								onSelect: function () {
									
								
								}
							}); 
						} 
					} 
				
				},
				{name:'nobl',index:'nobl', width:160},
				{name:'tglbl',index:'tglbl', width:160},
				{name:'kode_supplier',index:'kode_supplier', width:160},
				{name:'order_no',index:'order_no', width:160},
				{name:'order_date',index:'order_date', width:160},
				{name:'status_data',index:'status_data', width:160, formatter:myformatter,stype:"select",editoptions:{value:"-:;new:new;data processed bc:data processed bc;all:All"}},
				
			],
			rowNum:10,
			rowList:[10,20,30, 100, 500, 1000, 2000,5000],
			pager: '#ptbl_proses_inv_mesinsparepart_hdr',
			sortname: 'invoice_no',
			viewrecords: true,
			sortorder: "desc",
			width: 850,
			height:280,
			jsonReader: { repeatitems : false },
			caption:"Invoice Terproses",
			rownumbers: true,
			shrinkToFit: false,
			multiselect: true,
			loadOnce:true,
			cellEdit: true, 
			cellsubmit: 'clientArray',
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				
				var rowIDs = jQuery("#tbl_proses_inv_mesinsparepart").getDataIDs(); 
				var rowData = $("#tbl_proses_inv_mesinsparepart").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_proses_inv_mesinsparepart'));
				   
					switch (rowData[i].status_upload) {
						
						/* case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'Data Processed':
						   trElement.css({"color":"blue"});
						break; */
						
						
					}
				}
			},
			onSelectRow: function (rowid, status) {
			
				
			},
			loadComplete: function () {
			
			
			},
		}); 
		
		
		
		$grid.jqGrid('navGrid','#ptbl_proses_inv_mesinsparepart_hdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		$grid.jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		
		$("#btnviewdetilinvoicemesinprosesbc23_bc23").button().click(function(){
			
			var ids = $grid.getGridParam('selarrrow');
			var count = ids.length;
			var xxx;
		 	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 = $grid.jqGrid('getRowData', ids[i]);
				//names.push(rowData.invoice_no);	
				names.push(rowData);
				
			}} else {
				alert('Silakan Cek/Pilih Datanya Dahulu');
				return false;
				
			}
			//alert(JSON.stringify(names));
			//alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));  
			
			var postData = JSON.stringify(names);
			
			/* console.log(postData);
			return false; */
			
			
			if (postData == '' || postData=='undefined'){
				alert('Silakan Cek/Pilih Datanya Dahulu');
				return false;
			}
			var form_data = {
				parmeter:'parameter',
				postData:postData
			};
			
			$("#view_invoicemesindlg").load('<?php echo base_url().'exim/ct_bc23/view_bc23_detil_invoicemesin'; ?>', form_data, function() {
				$("#view_invoicemesindlg").dialog({
					modal:true,
					width : 900,
					height : 550,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#view_invoicemesindlg').dialog("destroy"); 
					    $(".view_invoicemesindlg_cl").remove(); 
					    $("body").append('<div id="view_invoicemesindlg" title="INVOICE DATA MESIN" class="view_invoicemesindlg_cl"></div>'); 
						$('#tblbc23hdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		
		$("#btnupdateinvoicemesinproses_bc23").button().click(function(){
			var ids = $grid.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 = $grid.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_update_date_inv_mesinsparepart_dtl").dialog( "destroy" );
			$(".dlg_update_date_inv_mesinsparepart_dtl_cl").remove();
			$(".dlg_update_date_inv_mesinsparepart_dtl_cl").html('');
			$("body").append('<div id="dlg_update_date_inv_mesinsparepart_dtl" title="Warning" class="dlg_update_date_inv_mesinsparepart_dtl_cl"><p>Apakah anda yakin akan melakukan update data mesin sparepart  ..?</p><br />Mohon diperiksa kembali datanya.</div>');
			$("#dlg_update_date_inv_mesinsparepart_dtl").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23/proses_update_inv_mesinsparepart'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_update_date_inv_mesinsparepart_dtl").dialog("close");
								$('#dlg_update_date_inv_mesinsparepart_dtl').dialog("destroy"); 
								$(".dlg_update_date_inv_mesinsparepart_dtl_cl").remove(); 
								$(".dlg_update_date_inv_mesinsparepart_dtl_cl").html('');
								$grid.trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_update_date_inv_mesinsparepart_dtl").dialog("close");
								$('#dlg_update_date_inv_mesinsparepart_dtl').dialog("destroy"); 
								$(".dlg_update_date_inv_mesinsparepart_dtl_cl").remove(); 
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_update_date_inv_mesinsparepart_dtl" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_update_date_inv_mesinsparepart_dtl').dialog("destroy"); 
					$(".dlg_update_date_inv_mesinsparepart_dtl_cl").remove(); 
					//$("body").append('<div id="dlg_update_date_inv_mesinsparepart_dtl" title="Warning" class="dlg_update_date_inv_mesinsparepart_dtl_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename  +'..?</p><br />Mohon diperiksa kembali datanya.</div>.</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		$("#btnprosesinvoicemesinproses_bc23").button().click(function(){
			var ids = $grid.getGridParam('selarrrow');
			var count = ids.length;
			var xxx;
		 	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 = $grid.jqGrid('getRowData', ids[i]);
				//names.push(rowData.invoice_no);	
				names.push(rowData);
				
			}} else {
				alert('Silakan Cek/Pilih Datanya Dahulu');
				return false;
				
			}
			//alert(JSON.stringify(names));
			 //alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));  
			
			
			var postData = JSON.stringify(names);
			
			if (postData == '' || postData=='undefined'){
				alert('Silakan Cek/Pilih Datanya Dahulu');
				return false;
			}
			var form_data = {
				parmeter:'parameter',
				postData:postData
			};
			$("#dlg_prosesbc23_mesinsparepart_dtl").dialog( "destroy" );
			$(".dlg_prosesbc23_mesinsparepart_dtl_cl").remove();
			$(".dlg_prosesbc23_mesinsparepart_dtl_cl").html('');
			$("body").append('<div id="dlg_prosesbc23_mesinsparepart_dtl" title="Warning" class="dlg_prosesbc23_mesinsparepart_dtl_cl"><p>Apakah anda yakin akan melakukan proses BC23 data mesin sparepart ..?</p><br /><b>Mohonnn banget periksa datanya biar ga salah</b><br />Sesuai BL Terpilih<br />Mohon diperiksa kembali datanya.</div>');
			$("#dlg_prosesbc23_mesinsparepart_dtl").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23/proses_bc23_mesinsparepart'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_prosesbc23_mesinsparepart_dtl").dialog("close");
								$('#dlg_prosesbc23_mesinsparepart_dtl').dialog("destroy"); 
								$(".dlg_prosesbc23_mesinsparepart_dtl_cl").remove(); 
								$(".dlg_prosesbc23_mesinsparepart_dtl_cl").html('');
								$grid.trigger('reloadGrid');
								jQuery("#tblbc23hdr").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_prosesbc23_mesinsparepart_dtl").dialog("close");
								$('#dlg_prosesbc23_mesinsparepart_dtl').dialog("destroy"); 
								$(".dlg_prosesbc23_mesinsparepart_dtl_cl").remove(); 
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_prosesbc23_mesinsparepart_dtl" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_prosesbc23_mesinsparepart_dtl').dialog("destroy"); 
					$(".dlg_prosesbc23_mesinsparepart_dtl_cl").remove(); 
					//$("body").append('<div id="dlg_prosesbc23_mesinsparepart_dtl" title="Warning" class="dlg_prosesbc23_mesinsparepart_dtl_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename  +'..?</p><br />Mohon diperiksa kembali datanya.</div>.</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
			
			
			
        });
		
		
		/* khusus kurir*/
		$("#btnproses_kurir_bc23").button().click(function(){
		
			$("#frmkurir_load").load('<?php echo base_url().'exim/ct_bc23/view_bc23_kurir_load'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmkurir_load").dialog({
					modal:true,
					width : 800,
					height : 520,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmkurir_load').dialog("destroy"); 
					    $(".frmkurir_load_cl").remove(); 
					    $("body").append('<div id="frmkurir_load" title="TARIK LOAD DATA KURIR" class="frmkurir_load_cl"></div>'); 
						//$('#tblbc23hdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});		
		
		
		});
		
		
		/* end kurir */
	
	});
		  	
</script>
<div id="view_invoicemesindlg" title="INVOICE DATA MESIN" class="view_invoicemesindlg_cl"></div>
<div id="frmkurir_load" title="TARIK LOAD DATA KURIR" class="frmkurir_load_cl"></div>



	
	