	<?php
        $this->load->view('admin/master/header_2');
		$modul=$this->uri->segment(3);
		$menuid=$this->uri->segment(4);
    ?>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            Work Order
            <small>Control panel</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="<?php echo base_url();?>admin/home/index/8"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="<?php echo base_url();?>admin/transaction/stock/<?php echo $menuid;?>">Work Order</a></li>
            <li class="active">Insert</li>
        </ol>
    </section>
    <section class="content">
    	<?php echo $this->session->flashdata('message') ?>
        <?php echo $this->session->flashdata('mdt') ?>
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">Filter</h3>
                        <hr>
                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                        </div>
                        <form action="<?php echo base_url();?>admin/transaction/insert_workorder/<?php echo $menuid;?>" method="post" enctype="multipart/form-data">
				            <div class="body">
				              	<div class="row clearfix">
					                <div class="col-md-4">
					                	<div class="form-group">
					                		<div class="form-line">
						                        <label>Work Order No <font color="#f00">*</font></label>
						                        <?php
													$wo=$this->master_model->wo();
												?>
						                        <input type="text" name="workorder" class="form-control" placeholder="Purchase Order No" disabled="disabled" required="required" value="<?php echo $wo;?>">
						                    </div>
					                    </div>
					                    <div class="form-group">
					                    	<div class="form-line">
						                        <label>Schedule Date <font color="#f00">*</font></label>
						                        <?php
													$today=strtotime(date('Y-m-d'));
													$today=date('m/d/Y', $today);
												?>
						                        <input type="text" name="schedule_date" id="datepicker" class="form-control" placeholder="Date" value="<?php echo $today;?>" required="required">
						                    </div>
						                    <script type="text/javascript">
						                    	$(function(){
						                    		$("#datepicker").datepicker();
						                    	});
						                    </script>
					                    </div>
					                    <div class="form-group">
					                    	<div class="form-line">
						                        <label>Target Date <font color="#FF0000">*</font></label>
						                        <?php
													$required=strtotime(date('Y-m-d'));
													$required=strtotime('+30 day', $required);
													$required=date('m/d/Y', $required);
												?>
						                        <input type="text" name="target_date" id="datepicker2" class="form-control" placeholder="Date" value="<?php echo $today;?>" required="required">
						                    </div>
						                    <script type="text/javascript">
						                    	$(function(){
						                    		$("#datepicker2").datepicker();
						                    	});
						                    </script>
					                    </div>
					                </div>
					                <div class="col-md-4">
					                	<div class="form-group">
					                    	<div class="form-line">
					                        	<label>Product Code</label><font color="#FF0000">*</font>
							                        <script>
														$(document).ready(function()
								                            {
								                            	exist2 = 0;
								                              	$("#product_code").change(function (e){
								                                	var code = $(this).val();
								                                	$("#code-result").show();
									                                $.ajax({
									                                   type:"POST",
									                                   url: "<?php echo base_url();?>admin/master/check_code",
									                                   data:"code="+code,
									                                   success:function(msg)
									                                   {
									                                     if(msg == 1)
									                                     {
									                                       exist2 = 1;
									                                       $("#code-result").html('<font style="color:#2BB0EA"><i class="fa fa-check" style="color:#2DBE00"></i>code has not been used</font>');
									                                     }else if(msg==0)
									                                     {
									                                       exist2 = 0;
									                                       $("#code-result").html('<font style="color:#FF024F"><i class="fa fa-times"></i>code already in use</font>');
									                                     }else if(msg==2)
									                                     {
									                                       exist2 = 2;
									                                       $("#code-result").html('');
									                                     }
									                                   }
									                                });
								                              	});
								                              
								                              	$("#save").click(function(){
								                                	var code=$('#product_code').val();
								                                	if(code==0){
								                                  		return true;
								                                	}else{if(exist2 ==0){
									                                    alert('Kode Sudah Digunakan');
									                                    return false;
								                                  	}else{
								                                    	return true;
								                                  	}
								                                }
								                            }); 
								                        });
													</script>
												<span id="code-result" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
						                        <input type="text" name="product_code" maxlength='10' list="purchase_number" id="product_code" class="form-control" required="" placeholder="Product Code">
						                        <datalist id="purchase_number"></datalist>
						                    </div>
					                    </div>

					                    <div class="form-group">
					                    	<div class="form-line">
					                        	<label>Finish Good</label> <font color="#FF0000">*</font>
				                        		<script>
													$(document).ready(function(){
							                            exist2 = 0;
							                            $("#finish_good").change(function (e){
							                                var code = $(this).val();
							                                $("#code-result1").show();
							                                $.ajax({
							                                   	type:"POST",
							                                   	url: "<?php echo base_url();?>admin/master/check_name",
							                                   	data:"code="+code,
							                                   	success:function(msg){
							                                     	if(msg == 1){
							                                       		exist2 = 1;
							                                       		$("#code-result1").html('<font style="color:#2BB0EA"><i class="fa fa-check" style="color:#2DBE00"></i>Finish Good has not been used</font>');
							                                     	}else if(msg==0){
							                                       		exist2 = 0;
							                                       		$("#code-result1").html('<font style="color:#FF024F"><i class="fa fa-times"></i>Finish Good already in use</font>');
							                                     	}else if(msg==2){
							                                       		exist2 = 2;
							                                       		$("#code-result1").html('');
							                                     	}
							                                   	}
							                                });
							                            });
							                              
							                            $("#save").click(function(){
							                                var code=$('#finish_good').val();
							                                if(code==0){
							                                  	return true;
							                                }else{
							                                  	if(exist2 ==0){
							                                    	alert('Finish Good Sudah Digunakan');
							                                    	return false;
							                                  	}else{
							                                    	return true;
							                                  	}
							                                }
							                            });      
							                        });
												</script>

												<div class="input-group">
													<span id="code-result1" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
					                        		<input type="text" name="finish_good" class="form-control finish-good" id="finish_good" placeholder="Finish Good"/>
													<span class="input-group-btn">
														<button type="button" class="btn btn-default btn-flat search-finish-good" data-toggle="modal" data-target="#finish-good-modal">
															<i class="fa fa-fw fa-search"></i>
														</button>
													</span>
												</div>
													<script>
														$(".search-finish-good").click(function(){
															$.ajax({
																type: "POST",
																dataType: "html",
																url: "<?php echo base_url();?>admin/transaction/get_code_from_babykenaz/<?php echo $menuid;?>",
																 //data:"finish="+finish,
																success: function(msg){
																	$(".finish-good-content").html(msg);
																}
															});
														});
													</script>

													<script>
														$('.save').click(function(){
															var code = $('[name="finish_good"]').val();
															$.ajax({
												          		type: "GET",
												          		url: "https://babykenaz.com/api/product_models/status?code="+code+"&status=On Production",
												          		//data: data,
												          		dataType: "json",
												          		cache : false,
												          		success: function(response){
												            		return true;
												          		}
												      		});
														});
													</script>
					                    		</div>
						                	</div>
						                    <div class="form-group">
						                    	<div class="form-line">
						                        	<label>Sales Order No</label>
								                        <script>
															$(document).ready(function(){
																$(".purchase_number").bind('input', function(e){
																	var number = $(this).val();
																	$.ajax({
																		type: "GET",
																		dataType: "html",
																		url: "<?php echo base_url();?>admin/transaction/get_purchase_number/<?php echo $menuid;?>",
																		data:"number="+number,
																		success: function(msg){
																			$("#purchase_number").html(msg);
																		}
																	});
																});

																$(".purchase_get_detail").focusout(function(e){
																	var number = $(this).val();

																	$.ajax({
																		type: "POST",
																		dataType: "html",
																		url: "<?php echo base_url();?>admin/transaction/purchase_get_detail_2/<?php echo $menuid;?>",
																		data:"number="+number,
																		success: function(msg){
																			$(".purchase_detail").html(msg);
																		}
																	});

																	$.ajax({
																		type: "POST",
																		dataType: "html",
																		url: "<?php echo base_url();?>admin/transaction/purchase_get_service/<?php echo $menuid;?>",
																		data:"number="+number,
																		success: function(msg){
																			$(".purchase_service").html(msg);
																		}
																	});
																});
															});
														</script>
							                        <input type="text" name="sales_order_no" list="purchase_number" id="purchase_numbers" class="form-control" placeholder="Sales Order No">
							                        <datalist id="purchase_number"></datalist>
							                    </div>
						                    </div>
						                    <div class="form-line">
					                        	<label>Customer</label>
					                        		<!-- <span id="code-supplier-result" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
					                        		<input type="text" name="supplier_code" list="supplier_code" class="form-control supplier_code supplier_get_detail" placeholder="Supplier Code" id="supplier_code_2" required="required">
					                        	<datalist id="supplier_code"></datalist> -->
					                        	<select class="form-control supplier_get" name="supplier_code" style="width: 100%;">
										              <option value="">Select Customer</option>
										              <?php foreach ($customer as $key => $value): ?>
										              		<option value="<?php echo $value->ID ?>">
										                      <?php echo $value->code.' - '.$value->name; ?>
										                    </option>
										              <?php endforeach ?>
										              
										        </select>
					                        </div>
						                    <div class="col-md-6">
						                    	<div class="row">
							                        <div class="form-group">
							                        	<script>
															$(document).ready(function()
															{
																$(".supplier_code").bind('input', function(e)
																{
																	var code = $(this).val();
																	$.ajax({
																		 type: "GET",
																		 dataType: "html",
																		 url: "<?php echo base_url();?>admin/transaction/get_customer/<?php echo $menuid;?>",
																		 data:"code="+code,
																		 success: function(msg)
																		 {
																			$("#supplier_code").html(msg);
																		 }
																	}); 				  
																});
																
																$(".supplier_get_detail").focusout(function(e)
																{
																	var code = $(this).val();
																	$.ajax({
																		 type: "POST",
																		 dataType: "html",
																		 url: "<?php echo base_url();?>admin/transaction/customer_get_detail/<?php echo $menuid;?>",
																		 data:"code="+code,
																		 success: function(msg)
																		 {
																			if(code=='')
																			{
																				$("#supplier_name_2").val('');
																				$(".payment_terms").val('');
																			}else
																			{
																				var data_supplier = msg;
																				var explode = data_supplier.split("%");
																				
																				var supplier_name  = explode[0];
																				var payment_terms  = explode[1];
																				var check   	   = explode[2];
																				var st   		   = explode[3];
																				
																				if(check=='exist')
																				{
																					$("#supplier_name_2").val(supplier_name);
																					$(".payment_terms").val(payment_terms);
																					if(st == 1)
																					{
																						$(".st").val('Yes');
																					} else {
																						$(".st").val('NO');
																					}
																				}else
																				{
																					var x = document.getElementById("snackbar")
																					x.className = "show";
																					x.innerHTML = "Supplier does not exist!";
																					setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																					
																					$("#supplier_name_2").val('');
																					$("#supplier_code_2").val('');
																					$(".payment_terms").val('');
																				}
																			}
																		 }
																	}); 				  
																});
															});
														</script>
														
							                        </div>
						                    	</div>
						                    </div>
						                    <!-- <div class="col-md-6">
						                    	<div class="row">
						                        	<div class="form-group">
							                            <script>
															$(document).ready(function()
															{
																$(".supplier_name").bind('input', function(e)
																{
																	var name = $(this).val();
																	$.ajax({
																		 type: "GET",
																		 dataType: "html",
																		 url: "<?php echo base_url();?>admin/transaction/get_customer_2/<?php echo $menuid;?>",
																		 data:"name="+name,
																		 success: function(msg)
																		 {
																			$("#supplier_name").html(msg);
																		 }
																	}); 				  
																});
																
																$(".supplier_get_detail_2").focusout(function(e)
																{
																	var name = $(this).val();
																	
																	$.ajax({
																		 type: "POST",
																		 dataType: "html",
																		 url: "<?php echo base_url();?>admin/transaction/customer_get_detail_2/<?php echo $menuid;?>",
																		 data:"name="+name,
																		 success: function(msg)
																		 {
																			if(name=='')
																			{
																				$("#supplier_code_2").val('');
																				$(".payment_terms").val('');
																			}else
																			{
																				var data_supplier = msg;
																				var explode = data_supplier.split("%");
																				
																				var supplier_code  = explode[0];
																				var payment_terms  = explode[1];
																				var check   		  = explode[2];
																				var st   		  = explode[3];
																				
																				if(check=='exist')
																				{
																					$("#supplier_code_2").val(supplier_code);
																					$(".payment_terms").val(payment_terms);
																					if(st == 1)
																					{
																						$(".st").val('Yes');
																					} else {
																						$(".st").val('NO');
																					}
																				}else
																				{
																					var x = document.getElementById("snackbar")
																					x.className = "show";
																					x.innerHTML = "Supplier does not exist!";
																					setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																					
																					$("#supplier_name_2").val('');
																					$("#supplier_code_2").val('');
																					$(".payment_terms").val('');
																				}
																			}
																		 }
																	}); 				  
																});
															});
														</script>
														<div class="form-line">
							                        		<label>Customer Name</label>
																<span id="name-supplier-result" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
							                        			<input type="text" name="supplier_name" list="supplier_name" id="supplier_name_2" class="form-control supplier_name supplier_get_detail_2" placeholder="Supplier Name" required="required">
							                        			<datalist id="supplier_name"></datalist>
							                    		</div>
						                       		 </div>
						                    	</div>
						                    </div> -->
					                	</div>
						                <div class="col-md-4">
						                    <div class="form-group">
						                    	<div class="form-line">
							                        <label>Target Pcs <font color="#FF0000">*</font></label>
							                        <input type="text" name="target_pcs" class="form-control" placeholder="Pcs" required/>
							                    </div>
						                    </div>
						                    <div class="col-md-6">
						                        <div class="form-group">
						                        	<div class="form-line">
							                            <label>Status</label>
							                            <br />
							                            Pending
							                            <br />
							                            <br />
							                        </div>
							                        
							                            <label>Cost</label>
							                            <br />
							                        <div class="form-line">
							                            <input type="text" class="form-control" name="harga_awal" style="margin-bottom: 10px;">
							                        </div>
							                        <div class="form-line">
							                            <label>HPP</label>
							                            <br />
						                            		0
						                           	</div>
						                        </div>
						                    </div>
						                    <div class="col-md-6">
						                    	<div class="form-group">
						                    		<div class="form-line">
							                            <label>Total Material</label>
							                            <br />
							                            0
							                            <br />
							                            <br />
							                        </div>
							                        <div class="form-line">
							                            <label>Total Labour</label>
							                            <br />
							                            0
							                            <br />
							                            <br />
							                        </div>
							                        <div class="form-line">
							                            <label>Grand Total</label>
							                            <br />
							                            0
							                        </div>
						                        </div>
						                    </div>
						                </div>
				              		</div>
					               	<div class="nav-tabs-custom">
					                    <ul class="nav nav-tabs">
					                    	<li class="active"><a href="#tab_1" data-toggle="tab">Direct Material</a></li>
					                    	<li><a href="#tab_2" data-toggle="tab">Labour</a></li>
					                    	<li><a href="#tab_3" data-toggle="tab">Design</a></li>
					                    </ul>
					                    <div class="tab-content">
					                    	<div class="tab-pane active" id="tab_1">
					                        	<div class="row">
					                                <div class="col-md-12">
					                                	<div class="table-responsive">
                											<table class="table table-bordered table-striped table-hover js-basic-example dataTable">
						                                        <thead>
						                                            <tr>
						                                                <th>No.</th>
						                                                <th>Code</th>
						                                                <th>Description</th>
						                                                <th>Plan</th>
						                                                <th>Available</th>
						                                                <th>Requested</th>
						                                                <th>Actual</th>
						                                                <th>Return</th>
						                                                <th>Unit Price</th>
						                                                <th>Gross Ammount</th>
						                                                <th>Delete</th>
						                                            </tr>
						                                        </thead>
						                                        <tbody>
						                                        	<?php
																		for($c=0; $c < 5; $c++){
																			$d=$c+1;

																			if($d==1){
																				$required='required="required"';
																			}else{
																				$required='';
																			}
																	?>
						                                        	<tr>
						                                                <td>
						                                                    <?php echo $d;?>
						                                                </td>
						                                                <td>
																			<script>
						                                                        $(document).ready(function(){
						                                                            $(".inventory_code_<?php echo $d;?>").bind('input', function(e){
						                                                                var code = $(this).val();
						                                                                $.ajax({
						                                                                    type: "GET",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/get_code_inventory/<?php echo $menuid;?>",
						                                                                    data:"code="+code,
						                                                                    success: function(msg){
						                                                                        $("#inventory_code_<?php echo $d;?>").html(msg);
						                                                                    }
						                                                                });
						                                                            });
						                                                            $(".inventory_get_qty_<?php echo $d;?>").focusout(function(e){
						                                                                var code = $(this).val();
						                                                                $.ajax({
						                                                                    type: "POST",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/inventory_get_qty/<?php echo $menuid;?>",
						                                                                    data:"code="+code,
						                                                                    success: function(msg){
						                                                                        var x = document.getElementById("snackbar")
						                                                                        x.className = "show";
						                                                                        x.innerHTML = "Field Available "+msg;
						                                                                        setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
						                                                                        console.log(msg)

						                                                                        $(".available_<?php echo $d;?>").html(msg);
						                                                                    }
						                                                                });
						                                                            });
						                                                            $(".inventory_get_detail_<?php echo $d;?>").focusout(function(e)
						                                                            {
						                                                                var code = $(this).val();
						                                                                $.ajax({
						                                                                    type: "POST",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/inventory_get_detail_3_/<?php echo $menuid;?>",
						                                                                    data:"code="+code,
						                                                                    success: function(msg){
						                                                                        if(code==''){
						                                                                            $("#inventory_names_<?php echo $d;?>").val('');
						                                                                            $("#qty_<?php echo $d;?>").val(0);
						                                                                        }else{
						                                                                            var data_inventory = msg;
						                                                                            var explode = data_inventory.split("%");
						                                                                            var inventory_name  = explode[0];
						                                                                            var plan  		    = explode[1];
						                                                                            var check   		   = explode[2];
						                                                                            if(check=='exist'){
						                                                                                $("#inventory_names_<?php echo $d;?>").val(inventory_name);
																										$(".plan_<?php echo $d;?>").html(plan);
						                                                                            }else{
						                                                                                $("#inventory_names_<?php echo $d;?>").val('');
																										$(".plan_<?php echo $d;?>").html('<input type="text" name="plan[]" class="form-control" style="width:100px;" />');
						                                                                                var x = document.getElementById("snackbar")
						                                                                                x.className = "show";
						                                                                                x.innerHTML = "Item does not exist!";
						                                                                                setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
						                                                                            }
						                                                                        }
						                                                                    }
						                                                                });
						                                                            });
						                                                        });
						                                                    </script>
						                                                    <input type="text" name="code_material[]" placeholder="Code" list="inventory_code_<?php echo $d;?>" id="inventory_codes_<?php echo $d;?>" class="form-control inventory_code_<?php echo $d;?> inventory_get_detail_<?php echo $d;?> inventory_get_qty_<?php echo $d;?>" style="width:100px" />
						                                                    <datalist id="inventory_code_<?php echo $d;?>"></datalist>
						                                                </td>
						                                                <td>
						                                                    <script>
						                                                        $(document).ready(function(){
						                                                            $(".inventory_name_<?php echo $d;?>").bind('input', function(e){
						                                                                var name = $(this).val();
						                                                                $.ajax({
						                                                                    type: "GET",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/get_name_inventory/<?php echo $menuid;?>",
						                                                                    data:"name="+name,
						                                                                    success: function(msg){
						                                                                        $("#inventory_name_<?php echo $d;?>").html(msg);
						                                                                    }
						                                                                });
						                                                            });
						                                                            $(".inventory_name_get_detail_<?php echo $d;?>").focusout(function(e){
						                                                                var name = $(this).val();
						                                                                $.ajax({
						                                                                    type: "POST",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail_3_/<?php echo $menuid;?>",
						                                                                    data:"name="+name,
						                                                                    success: function(msg){
						                                                                        if(name==''){
						                                                                            $("#inventory_codes_<?php echo $d;?>").val('');
						                                                                            $("#qty_<?php echo $d;?>").val(0);
						                                                                        }else{
						                                                                            var data_inventory = msg;
						                                                                            var explode = data_inventory.split("%");
						                                                                            var inventory_code  = explode[0];
						                                                                            var plan  			 = explode[1];
						                                                                            var check   		   = explode[2];
						                                                                            if(check=='exist'){
						                                                                                $("#inventory_codes_<?php echo $d;?>").val(inventory_code);
						                                                                                $(".plan_<?php echo $d;?>").html(plan);
						                                                                            }else{
						                                                                                $("#inventory_codes_<?php echo $d;?>").val('');
						                                                                                $(".plan_<?php echo $d;?>").html('<input type="text" name="plan[]" class="form-control" style="width:100px;" />');

						                                                                                var x = document.getElementById("snackbar")
						                                                                                x.className = "show";
						                                                                                x.innerHTML = "Item does not exist!";
						                                                                                setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
						                                                                            }
						                                                                        }
						                                                                    }
						                                                                });
						                                                            });
						                                                        });
						                                                    </script>
						                                                    <input type="text" name="item_material[]" list="inventory_name_<?php echo $d;?>" placeholder="Item" id="inventory_names_<?php echo $d;?>" class="form-control inventory_name_<?php echo $d;?> inventory_name_get_detail_<?php echo $d;?> inventory_name_get_qty_<?php echo $d;?>" style="width:250px"/>
						                                                    <datalist id="inventory_name_<?php echo $d;?>"></datalist>
						                                                </td>
						                                                <td align="center" class="plan_<?php echo $d;?>">
						                                                	<input type="text" name="plan[]" class="form-control" style="width:100px;" />
						                                                </td>
						                                                <td align="center" class="available_<?php echo $d;?>">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                	<button type="button" class="btn btn-xs btn-danger hapus-row"><i class="material-icons">clear</i></button>
						                                                	<script type="text/javascript">
						                                                		$(document).on('click', '.hapus-row', function(){
																			        $(this).parent().parent().remove();
																			    });
						                                                	</script>
						                                                </td>
						                                            </tr>
							                                            <?php
																			}
																		?>
							                                            <?php
																			for($a=0; $a < 5; $a++)
																			{
																				$b=$a+6;
																		?>
																	<tr id="row3<?php echo $b;?>" style="display:none">
						                                                <td>
						                                                    <?php echo $b;?>
						                                                </td>
						                                                <td>
																			<script>
						                                                        $(document).ready(function(){
						                                                            $(".inventory_code_<?php echo $b;?>").bind('input', function(e){
						                                                                var code = $(this).val();
						                                                                $.ajax({
						                                                                    type: "GET",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/get_code_inventory/<?php echo $menuid;?>",
						                                                                    data:"code="+code,
						                                                                    success: function(msg){
						                                                                        $("#inventory_code_<?php echo $b;?>").html(msg);
						                                                                    }
						                                                                });
						                                                            });
						                                                            $(".inventory_get_qty_<?php echo $b;?>").focusout(function(e){
						                                                                var code = $(this).val();
						                                                                $.ajax({
						                                                                    type: "POST",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/inventory_get_qty/<?php echo $menuid;?>",
						                                                                    data:"code="+code,
						                                                                    success: function(msg){
						                                                                        var x = document.getElementById("snackbar")
						                                                                        x.className = "show";
						                                                                        x.innerHTML = "Field Available "+msg;
						                                                                        setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
						                                                                        console.log(msg)

						                                                                        $(".available_<?php echo $b;?>").html(msg);
						                                                                    }
						                                                                });
						                                                            });
						                                                            $(".inventory_get_detail_<?php echo $b;?>").focusout(function(e)
						                                                            {
						                                                                var code = $(this).val();
						                                                                $.ajax({
						                                                                    type: "POST",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/inventory_get_detail_3/<?php echo $menuid;?>",
						                                                                    data:"code="+code,
						                                                                    success: function(msg){
						                                                                        if(code==''){
						                                                                            $("#inventory_names_<?php echo $b;?>").val('');
						                                                                            $("#qty_<?php echo $b;?>").val(0);
						                                                                        }else{
						                                                                            var data_inventory = msg;
						                                                                            var explode = data_inventory.split("%");
						                                                                            var inventory_name  = explode[0];
						                                                                            var plan  		    = explode[1];
						                                                                            var check   		   = explode[2];
						                                                                            if(check=='exist'){
						                                                                                $("#inventory_names_<?php echo $b;?>").val(inventory_name);
																										$(".plan_<?php echo $b;?>").html(plan);
						                                                                            }else{
						                                                                                $("#inventory_names_<?php echo $b;?>").val('');
																										$(".plan_<?php echo $b;?>").html('<input type="text" name="plan[]" class="form-control" style="width:100px;" />');
						                                                                                var x = document.getElementById("snackbar")
						                                                                                x.className = "show";
						                                                                                x.innerHTML = "Item does not exist!";
						                                                                                setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
						                                                                            }
						                                                                        }
						                                                                    }
						                                                                });
						                                                            });
						                                                        });
						                                                    </script>
						                                                    <input type="text" name="code_material[]" placeholder="Code" list="inventory_code_<?php echo $b;?>" id="inventory_codes_<?php echo $b;?>" class="form-control inventory_code_<?php echo $b;?> inventory_get_detail_<?php echo $b;?> inventory_get_qty_<?php echo $b;?>" style="width:100px"/>
						                                                    <datalist id="inventory_code_<?php echo $b;?>"></datalist>
						                                                </td>
						                                                <td>
						                                                    <script>
						                                                        $(document).ready(function(){
						                                                            $(".inventory_name_<?php echo $d;?>").bind('input', function(e){
						                                                                var name = $(this).val();
						                                                                $.ajax({
						                                                                    type: "GET",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/get_name_inventory/<?php echo $menuid;?>",
						                                                                    data:"name="+name,
						                                                                    success: function(msg){
						                                                                        $("#inventory_name_<?php echo $d;?>").html(msg);
						                                                                    }
						                                                                });
						                                                            });
						                                                            $(".inventory_name_get_detail_<?php echo $d;?>").focusout(function(e){
						                                                                var name = $(this).val();
						                                                                $.ajax({
						                                                                    type: "POST",
						                                                                    dataType: "html",
						                                                                    url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail_3/<?php echo $menuid;?>",
						                                                                    data:"name="+name,
						                                                                    success: function(msg){
						                                                                        if(name==''){
						                                                                            $("#inventory_codes_<?php echo $d;?>").val('');
						                                                                            $("#qty_<?php echo $d;?>").val(0);
						                                                                        }else{
						                                                                            var data_inventory = msg;
						                                                                            var explode = data_inventory.split("%");
						                                                                            var inventory_code  = explode[0];
						                                                                            var plan  			 = explode[1];
						                                                                            var check   		   = explode[2];
						                                                                            if(check=='exist'){
						                                                                                $("#inventory_codes_<?php echo $d;?>").val(inventory_code);
						                                                                                $(".plan_<?php echo $d;?>").html(plan);
						                                                                            }else{
						                                                                                $("#inventory_codes_<?php echo $d;?>").val('');
						                                                                                $(".plan_<?php echo $d;?>").html('<input type="text" name="plan[]" class="form-control" style="width:100px;" />');

						                                                                                var x = document.getElementById("snackbar")
						                                                                                x.className = "show";
						                                                                                x.innerHTML = "Item does not exist!";
						                                                                                setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
						                                                                            }
						                                                                        }
						                                                                    }
						                                                                });
						                                                            });
						                                                        });
						                                                    </script>
						                                                    <input type="text" name="item_material[]" list="inventory_name_<?php echo $b;?>" placeholder="Item" id="inventory_names_<?php echo $b;?>" class="form-control inventory_name_<?php echo $b;?> inventory_name_get_detail_<?php echo $b;?> inventory_name_get_qty_<?php echo $b;?>" style="width:250px"/>
						                                                    <datalist id="inventory_name_<?php echo $b;?>"></datalist>
						                                                </td>
						                                                <td align="center" class="plan_<?php echo $b;?>">
						                                                	<input type="text" name="plan[]" class="form-control" style="width:100px;" />
						                                                </td>
						                                                <td align="center" class="available_<?php echo $b;?>">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td>
						                                                	<button type="button" class="btn btn-xs btn-danger hapus-row2"><i class="material-icons">clear</i></button>
						                                                	<script type="text/javascript">
						                                                		$(document).on('click', '.hapus-row2', function(){
																			        $(this).parent().parent().remove();
																			    });
						                                                	</script>
						                                                </td>
						                                                
						                                            </tr>
																	<?php
																		}
																	?>
						                                        </tbody>
						                                        <tfoot>
						                                            <tr>
						                                                <td colspan="8">
						                                                    <a class="btn btn-primary addOption loading_btn" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing">
						                                                        Add Row
						                                                    </a>
						                                                    <script>
						                                                        $('.loading_btn').on('click', function(){
						                                                            var $this = $(this);
						                                                            $this.button('loading');
						                                                            setTimeout(function()
						                                                            {
						                                                               $this.button('reset');
						                                                            }, 500);
						                                                        });
						                                                    </script>
						                                                    <script>
						                                                        $(document).ready(function(){
						                                                            var inc = 5;
						                                                            $(".addOption").on('click',function()
						                                                            {
						                                                                inc=inc+1;
						                                                                $("#row3"+inc+"").show();
						                                                            });
						                                                        });
						                                                    </script>
						                                                </td>
						                                            </tr>
						                                            <tr>
						                                                <td colspan="5">
						                                                    <strong>Note : </strong>
						                                                    <input type="text" name="note_material" class="form-control" />
						                                                </td>
						                                                <td colspan="5" valign="middle">
						                                                    <input type="submit" class="btn btn-info btn-fill pull-right save" value="Save" id="save" style="margin-top:10px;">
						                                                    <a href="<?php echo base_url();?>admin/transaction/workorder/<?php echo $menuid;?>" class="btn btn-danger pull-right" style="margin:10px 5px 0 0;">Cancel</a>
						                                                    <button type="reset" class="btn btn-default pull-right" style="margin:10px 5px 0 0;">Reset</button>
						                                                </td>
						                                            </tr>
						                                        </tfoot>
					                                    	</table>
					                                    </div>
					                                </div>
					                            </div>
					                    	</div>
					                        <div class="tab-pane" id="tab_2">
					                        	<div class="row">
					                                <div class="col-md-12" style="overflow: auto; white-space: nowrap;">
					                                	<div class="table-responsive">
						                                	<table class="table table-bordered table-striped table-hover js-basic-example dataTable">
						                                        <thead>
						                                            <tr>
						                                                <th>No.</th>
						                                                <th>Code</th>
						                                                <th>Description</th>
						                                                <th>Supplier Code</th>
						                                                <th>Supplier Name</th>
						                                                <th>Schedule Date</th>
						                                                <th>Target Date</th>
						                                                <th>Start Date</th>
						                                                <th>End Date</th>
						                                                <th>Requested</th>
						                                                <th>Done</th>
						                                                <th>Bad</th>
						                                                <th>Unit Price</th>
						                                                <th>Internal</th>
						                                                <th>Gross Ammount</th>
						                                                <th>Paid</th>
						                                            </tr>
						                                        </thead>
						                                        <tbody>
						                                        	<?php
																		for($c=0; $c < 5; $c++)
																		{
																			$d=$c+1;
																			$f=$c+40;
																			$g=$c+50;
																			if($d==1)
																			{
																				$required='required="required"';
																			}else
																			{
																				$required='';
																			}
																	?>
						                                            <tr>
						                                                <td>
						                                                    <?php echo $d;?>
						                                                </td>
						                                                <td>
						                                                	<script>
																				$(document).ready(function(){
																					$(".labour_code_<?php echo $d;?>").bind('input', function(e){
																						var code = $(this).val();
																						$.ajax({
																							type: "GET",
																							dataType: "html",
																							url: "<?php echo base_url();?>admin/transaction/get_code_inventory_2/<?php echo $menuid;?>",
																							data:"code="+code,
																							success: function(msg){
																								$("#labour_code_<?php echo $d;?>").html(msg);
																							}
																						});
																					});
																					$(".labour_get_detail_<?php echo $d;?>").focusout(function(e){
																						var code = $(this).val();
																						$.ajax({
																							type: "POST",
																							dataType: "html",
																							url: "<?php echo base_url();?>admin/transaction/inventory_get_detail_2/<?php echo $menuid;?>",
																							data:"code="+code,
																							success: function(msg){
																								if(code==''){
																									$("#labour_names_<?php echo $d;?>").val('');
																								}else{
																									var data_inventory = msg;
																									var explode = data_inventory.split("%");
																									var inventory_name  = explode[0];
																									var check   		   = explode[1];
																									if(check=='exist'){
																										$("#labour_names_<?php echo $d;?>").val(inventory_name);
																									}else{
																										$("#labour_names_<?php echo $d;?>").val('');
																										var x = document.getElementById("snackbar")
																										x.className = "show";
																										x.innerHTML = "Item does not exist!";
																										setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																									}
																								}
																							}
																						});
																					});
																				});
																			</script>
						                                                    <input type="text" name="code_labour[]" list="labour_code_<?php echo $d;?>" placeholder="Code" class="form-control labour_code_<?php echo $d;?> labour_get_detail_<?php echo $d;?>" id="labour_codes_<?php echo $d;?>" style="width:100px" value="" />
						                                                    <datalist id="labour_code_1"></datalist>
						                                                </td>
						                                                <td>
						                                                	<script>
																				$(document).ready(function(){
																					$(".labour_name_<?php echo $d;?>").bind('input', function(e){
																						var name = $(this).val();
																						$.ajax({
																							type: "GET",
																							dataType: "html",
																							url: "<?php echo base_url();?>admin/transaction/get_name_inventory_2/<?php echo $menuid;?>",
																							data:"name="+name,
																							success: function(msg){
																								$("#labour_name_<?php echo $d;?>").html(msg);
																							}
																						});
																					});
																					$(".labour_name_get_detail_<?php echo $d;?>").focusout(function(e){
																						var name = $(this).val();
																						$.ajax({
																							type: "POST",
																							dataType: "html",
																							url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail_2/<?php echo $menuid;?>",
																							data:"name="+name,
																							success: function(msg){
																								if(name==''){
																									$("#labour_codes_<?php echo $d;?>").val('');
																								}else{
																									var data_inventory = msg;
																									var explode = data_inventory.split("%");
																									var inventory_name  = explode[0];
																									var check   		   = explode[1];
																									if(check=='exist'){
																										$("#labour_codes_<?php echo $d;?>").val(inventory_name);
																									}else{
																										$("#labour_codes_<?php echo $d;?>").val('');
																										var x = document.getElementById("snackbar")
																										x.className = "show";
																										x.innerHTML = "Item does not exist!";
																										setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																									}
																								}
																							}
																						});
																					});
																				});
																			</script>
						                                                    <input type="text" name="item_labour[]" list="labour_name_<?php echo $d;?>" id="labour_names_<?php echo $d;?>" placeholder="Desc" class="form-control labour_name_<?php echo $d;?> labour_name_get_detail_<?php echo $d;?>" style="width:250px" value=""/>
						                                                    <datalist id="labour_name_1"></datalist>
						                                                </td>
						                                              	<td>
						                                        			<script>
												                                $(document).ready(function(){
												                                    $(".supplier_code<?php echo $d;?>").bind("input", function(e){
												                                        var code = $(this).val();
												                                        $.ajax({
												                                            type: "GET",
												                                            dataType: "html",
												                                            url: "<?php echo base_url();?>admin/transaction/get_supplier/<?php echo $menuid;?>",

												                                            data:"code="+code,
												                                            success: function(msg){
												                                                $("#supplier_code<?php echo $d;?>").html(msg);
												                                            }
												                                        });
												                                    });

												                                    $(".supplier_get_po_2<?php echo $d;?>").focusout(function(e){
												                                        var code = $(this).val();
																						$.ajax({
																							type: "POST",
																							dataType: "html",
																							url: "<?php echo base_url();?>admin/transaction/supplier_get_detail/<?php echo $menuid;?>",
																							data:"code="+code,
																							success: function(msg){
																								if(code==""){
																									$("#supplier_name_2<?php echo $d;?>").val("");
																									$(".payment_terms<?php echo $d;?>").val("");
																								}else{
																									var data_supplier = msg;
																									var explode = data_supplier.split("%");
																									var supplier_name  = explode[0];
																									var payment_terms  = explode[1];
																									var check   		  = explode[2];
																									if(check=="exist"){
																										$("#supplier_name_2<?php echo $d;?>").val(supplier_name);
																									}else{
																										$("#supplier_code_2<?php echo $d;?>").val("");
																										$("#supplier_name_2<?php echo $d;?>").val("");

																										var x = document.getElementById("snackbar")
																										x.className = "show";
																										x.innerHTML = "Supplier code is missing!";
																										setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																									}
																								}
																							}
																						});
												                                    });
												                                });
												                            </script>
												                            <input type="text" name="supplier_code_labour[]" list="supplier_code<?php echo $d;?>" id="supplier_code_2<?php echo $d;?>" class="form-control supplier_code<?php echo $d;?> supplier_get_po_2<?php echo $d;?>" placeholder="Supplier Code">
												                            <datalist id="supplier_code<?php echo $d;?>"></datalist>
						                                                </td>
						                                                <td>
						                                        			<script>
												                                $(document).ready(function(){
												                                    $(".supplier_name<?php echo $d;?>").bind("input", function(e){
												                                        var name = $(this).val();
												                                        $.ajax({
												                                            type: "GET",
												                                            dataType: "html",
												                                            url: "<?php echo base_url();?>admin/transaction/get_supplier_2/<?php echo $menuid?>",
												                                            data:"name="+name,
												                                            success: function(msg){
												                                                $("#supplier_name<?php echo $d;?>").html(msg);
												                                            }
												                                        });
												                                    });
												                                    $(".supplier_get_po<?php echo $d;?>").focusout(function(e){
												                                        var name = $(this).val();
																						$.ajax({
																							type: "POST",
																							dataType: "html",
																							url: "<?php echo base_url();?>admin/transaction/supplier_get_detail_2/<?php echo $menuid?>",
																							data:"name="+name,
																							success: function(msg){
																								if(name==""){
																									$("#supplier_code_2<?php echo $d;?>").val("");
																								}else{
																									var data_supplier = msg;
																									var explode = data_supplier.split("%");
																									var supplier_code  = explode[0];
																									var payment_terms  = explode[1];
																									var check   	   = explode[2];
																									if(check=="exist"){
																										$("#supplier_code_2<?php echo $d;?>").val(supplier_code);
																									}else{
																										$("#supplier_name_2<?php echo $d;?>").val("");
																										$("#supplier_code_2<?php echo $d;?>").val("");
																										var x = document.getElementById("snackbar")
																										x.className = "show";
																										x.innerHTML = "Supplier name is missing!";
																										setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																									}
																								}
																							}
																						});
												                                    });
												                                });
												                            </script>
												                            <input type="text" name="supplier[]" list="supplier_name<?php echo $d;?>" id="supplier_name_2<?php echo $d;?>" class="form-control supplier_name<?php echo $d;?> supplier_get_po<?php echo $d;?>" placeholder="Supplier Name">
												                            <datalist id="supplier_name<?php echo $d;?>"></datalist>
						                                                </td>
						                                                <td>
						                                                    <input type="text" name="schedule[]" placeholder="Schedule" id="datepicker3"<?php echo $f;?> class="form-control datepicker3" style="width:100px" value=""/>
						                                                </td>
						                                                <script type="text/javascript">
													                    	$(function(){
													                    		$(".datepicker3").datepicker();
													                    	});
													                    </script>
						                                                <td>
						                                                    <input type="text" name="target[]" placeholder="Target" id="datepicker4"<?php echo $g;?> class="form-control datepicker3" style="width:100px"/>
						                                                    <script type="text/javascript">
													                    	$(function(){
													                    		$("#datepicker4").datepicker();
													                    	});
													                    </script>
						                                                </td>
						                                                <td align="center">
						                                                    -
						                                                </td>
						                                                <td align="center">
						                                                    -
						                                                </td>

						                                                <td align="center">
						                                                	0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td align="center">
						                                                    0
						                                                </td>
						                                                <td>
						                                                    <input type="text" name="price[]" placeholder="Price" class="form-control" style="width:100px"/>
						                                                </td>
						                                                <td align="center">
						                                                	<script>
																				$(function(){
																					$(".internal<?php echo $d;?>").click(function(){
																						var internal = $("#internal<?php echo $d;?>").val();
																						var x = document.getElementById("snackbar4")
																						x.className = "show";
																						x.innerHTML = "Internal success change!";
																						setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																						if(internal==0){
																							$("#change_icon<?php echo $d;?>").html('<i class="fa fa-check-square-o" aria-hidden="true"></i>');
																							$("#internal<?php echo $d;?>").val(1);
																						}else{
																							$("#change_icon<?php echo $d;?>").html('<i class="fa fa-square-o" aria-hidden="true"></i>');
																							$("#internal<?php echo $d;?>").val(0);
																						}
																					});
																				});
																			</script>
																			<a class="text-blue internal<?php echo $d;?>" id="change_icon<?php echo $d;?>" style="cursor:pointer">
																				<i class="fa fa-square-o" aria-hidden="true"></i>
																			</a>
						                                                    <input type="hidden" name="internal[]" value="0" id="internal<?php echo $d;?>" />
						                                                </td>
						                                                <td align="right">
						                                                    0
						                                                </td>
						                                                <td align="right">
						                                                    0
						                                                </td>
						                                            </tr>
						                                            <?php
																		}
																	?>
						                                            <?php
																		for($a=0; $a < 5; $a++)
																		{
																			$b=$a+6;
																			$h=$a+45;
																			$i=$a+55;
																			echo'
																				<tr id="row2'.$b.'" style="display:none">
																					<td>
																						'.$b.'
																					</td>
																					<td>
																						<script>
																							$(document).ready(function()
																							{
																								$(".labour_code_'.$b.'").bind("input", function(e)
																								{
																									var code = $(this).val();
																									$.ajax({
																										 type: "GET",
																										 dataType: "html",
																										 url: "'.base_url().'admin/transaction/get_code_inventory_2/'.$menuid.'",
																										 data:"code="+code,
																										 success: function(msg)
																										 {
																											$("#labour_code_'.$b.'").html(msg);
																										 }
																									});
																								});
																								$(".labour_get_detail_'.$b.'").focusout(function(e)
																								{
																									var code = $(this).val();
																									$.ajax({
																										 type: "POST",
																										 dataType: "html",
																										 url: "'.base_url().'admin/transaction/inventory_get_detail_2/'.$menuid.'",
																										 data:"code="+code,
																										 success: function(msg)
																										 {
																											if(code=="")
																											{
																												$("#labour_names_'.$b.'").val("");
																											}else
																											{
																												var data_inventory = msg;
																												var explode = data_inventory.split("%");
																												var inventory_name  = explode[0];
																												var check   		   = explode[1];
																												if(check=="exist")
																												{
																													$("#labour_names_'.$b.'").val(inventory_name);
																												}else
																												{
																													$("#labour_names_'.$b.'").val("");
																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Item does not exist!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										 }
																									});
																								});
																							});
																						</script>
																						<input type="text" name="code_labour[]" list="labour_code_'.$b.'" placeholder="Code" class="form-control labour_code_'.$b.' labour_get_detail_'.$b.'" id="labour_codes_'.$b.'" style="width:100px" value=""/>
																						<datalist id="labour_code_'.$b.'"></datalist>
																					</td>
																					<td>
																						<script>
																							$(document).ready(function()
																							{
																								$(".labour_name_'.$b.'").bind("input", function(e)
																								{
																									var name = $(this).val();
																									$.ajax({
																										 type: "GET",
																										 dataType: "html",
																										 url: "'.base_url().'admin/transaction/get_name_inventory_2/'.$menuid.'",
																										 data:"name="+name,
																										 success: function(msg)
																										 {
																											$("#labour_name_'.$b.'").html(msg);
																										 }
																									});
																								});
																								$(".labour_name_get_detail_'.$b.'").focusout(function(e)
																								{
																									var name = $(this).val();
																									$.ajax({
																										 type: "POST",
																										 dataType: "html",
																										 url: "'.base_url().'admin/transaction/inventory_name_get_detail_2/'.$menuid.'",
																										 data:"name="+name,
																										 success: function(msg)
																										 {
																											if(name=="")
																											{
																												$("#labour_codes_'.$b.'").val("");
																											}else
																											{
																												var data_inventory = msg;
																												var explode = data_inventory.split("%");
																												var inventory_name  = explode[0];
																												var check   		   = explode[1];
																												if(check=="exist")
																												{
																													$("#labour_codes_'.$b.'").val(inventory_name);
																												}else
																												{
																													$("#labour_codes_'.$b.'").val("");
																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Item does not exist!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										 }
																									});
																								});
																							});
																						</script>
																						<input type="text" name="item_labour[]" list="labour_name_'.$b.'" id="labour_names_'.$b.'" placeholder="Desc" class="form-control labour_name_'.$b.' labour_name_get_detail_'.$b.'" style="width:250px" value=""/>
																						<datalist id="labour_name_'.$b.'"></datalist>
																					</td>
																					<td>
									                                        			<script>
															                                $(document).ready(function()
															                                {
															                                    $(".supplier_code'.$b.'").bind("input", function(e)
															                                    {
															                                        var code = $(this).val();
															                                        $.ajax({
															                                             type: "GET",
															                                             dataType: "html",
															                                             url: "'.base_url().'admin/transaction/get_supplier/'.$menuid.'",
															                                             data:"code="+code,
															                                             success: function(msg)
															                                             {
															                                                $("#supplier_code'.$b.'").html(msg);
															                                             }
															                                        });
															                                    });
															                                    $(".supplier_get_po_2'.$b.'").focusout(function(e)
															                                    {
															                                        var code = $(this).val();
																									$.ajax({
																										 type: "POST",
																										 dataType: "html",
																										 url: "'.base_url().'admin/transaction/supplier_get_detail/'.$menuid.'",
																										 data:"code="+code,
																										 success: function(msg)
																										 {
																											if(code=="")
																											{
																												$("#supplier_name_2'.$b.'").val("");
																												$(".payment_terms'.$b.'").val("");
																											}else
																											{
																												var data_supplier = msg;
																												var explode = data_supplier.split("%");

																												var supplier_name  = explode[0];
																												var payment_terms  = explode[1];
																												var check   		  = explode[2];
																												if(check=="exist")
																												{
																													$("#supplier_name_2'.$b.'").val(supplier_name);
																												}else
																												{
																													$("#supplier_code_2'.$b.'").val("");
																													$("#supplier_name_2'.$b.'").val("");
																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Supplier code is missing!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										 }
																									});
															                                    });
															                                });
															                            </script>
															                            <input type="text" name="supplier_code_labour[]" list="supplier_code'.$b.'" id="supplier_code_2'.$b.'" class="form-control supplier_code'.$b.' supplier_get_po_2'.$b.'" placeholder="Supplier Code">
															                            <datalist id="supplier_code'.$b.'"></datalist>
									                                                </td>
									                                                <td>
									                                        			<script>
															                                $(document).ready(function()
															                                {
															                                    $(".supplier_name'.$b.'").bind("input", function(e)
															                                    {
															                                        var name = $(this).val();
															                                        $.ajax({
															                                             type: "GET",
															                                             dataType: "html",
															                                             url: "'.base_url().'admin/transaction/get_supplier_2/'.$menuid.'",
															                                             data:"name="+name,
															                                             success: function(msg)
															                                             {
															                                                $("#supplier_name'.$b.'").html(msg);
															                                             }
															                                        });
															                                    });
															                                    $(".supplier_get_po'.$b.'").focusout(function(e)
															                                    {
															                                        var name = $(this).val();
																									$.ajax({
																										 type: "POST",
																										 dataType: "html",
																										 url: "'.base_url().'admin/transaction/supplier_get_detail_2/'.$menuid.'",
																										 data:"name="+name,
																										 success: function(msg)
																										 {
																											if(name=="")
																											{
																												$("#supplier_code_2'.$b.'").val("");
																											}else
																											{
																												var data_supplier = msg;
																												var explode = data_supplier.split("%");
																												var supplier_code  = explode[0];
																												var payment_terms  = explode[1];
																												var check   	   = explode[2];
																												if(check=="exist")
																												{
																													$("#supplier_code_2'.$b.'").val(supplier_code);
																												}else
																												{
																													$("#supplier_name_2'.$b.'").val("");
																													$("#supplier_code_2'.$b.'").val("");
																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Supplier name is missing!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										 }
																									});
															                                    });
															                                });
															                            </script>
															                            <input type="text" name="supplier[]" list="supplier_name'.$b.'" id="supplier_name_2'.$b.'" class="form-control supplier_name'.$b.' supplier_get_po'.$b.'" placeholder="Supplier Name">
															                            <datalist id="supplier_name'.$b.'"></datalist>
									                                                </td>
																					<td>
																						<input type="text" name="schedule[]" placeholder="Schedule" id="datepicker'.$h.'" class="form-control" style="width:100px" value=""/>
																					</td>
																					<td>
																						<input type="text" name="target[]" placeholder="Target" id="datepicker'.$i.'" class="form-control" style="width:100px" value="'.$required.'"/>
																					</td>
																					<td align="center">
																						-
																					</td>
																					<td align="center">
																						-
																					</td>
																					<td align="center">
																						0
																					</td>
																					<!--
																					<td align="center">
																						0
																					</td>
																					<td align="center">
																						0
																					</td>
																					-->
																					<td align="center">
																						0
																					</td>
																					<td align="center">
																						0
																					</td>
																					<td>
																						<input type="text" name="price[]" placeholder="Price" class="form-control" style="width:100px"/>
																					</td>
																					<td align="center">
						                                                				<i class="fa fa-check text-green" aria-hidden="true"></i>
																					</td>
																					<td align="right">
																						0
																					</td>
																				</tr>
																			';
																		}
																	?>
						                                        </tbody>
						                                        <tfoot>
						                                            <tr>
						                                                <td colspan="11">
						                                                    <a class="btn btn-primary add_row loading_btn pull-left" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing">
						                                                        Add Row
						                                                    </a>
						                                                    <script>
						                                                        $('.loading_btn').on('click', function()
						                                                        {
						                                                            var $this = $(this);
						                                                            $this.button('loading');
						                                                            setTimeout(function()
						                                                            {
						                                                               $this.button('reset');
						                                                            }, 500);
						                                                        });
						                                                    </script>
						                                                    <script>
						                                                        $(document).ready(function()
						                                                        {
						                                                            var inc = 5;
						                                                            $(".add_row").on('click',function()
						                                                            {
						                                                                inc=inc+1;
						                                                                $("#row2"+inc+"").show();
						                                                            });
						                                                        });
						                                                    </script>
						                                                    <span class="pull-right">
						                                                    	<strong>Total :</strong>
						                                                    </span>
						                                                </td>
						                                                <td align="right">
						                                                    <strong>0</strong>
						                                                </td>

						                                            </tr>
						                                            <tr>
						                                                <td colspan="5">
						                                                    <strong>Note : </strong>
						                                                    <input type="text" name="note_labour" class="form-control" />
						                                                </td>
						                                                <td colspan="9" valign="middle">
						                                                    <input type="submit" class="btn btn-info btn-fill pull-right save" value="Save" id="save" style="margin-top:10px;">
						                                                    <a href="<?php echo base_url();?>admin/transaction/workorder/<?php echo $menuid;?>" class="btn btn-danger pull-right" style="margin:10px 5px 0 0;">Cancel</a>
						                                                    <button type="reset" class="btn btn-default pull-right" style="margin:10px 5px 0 0;">Reset</button>
						                                                </td>
						                                            </tr>
						                                        </tfoot>
						                                    </table>
						                                </div>
					                                </div>
					                            </div>
					                    	</div>
					                        <div class="tab-pane" id="tab_3">
					                        	<div class="row">
					                                <div class="col-md-12" style="overflow: auto; white-space: nowrap;">
					                                	<style>
															.img{
																max-width:80px;
															}
														</style>
														<div class="table-responsive">
						                                	<table class="table table-bordered table-striped"><!--purchase_service-->
						                                        <thead>
						                                        	<tr>
						                                            	<th>
						                                                	No.
						                                                </th>
						                                                <th>
						                                                	Image
						                                                </th>
						                                                <th>
						                                                	Preview
						                                                </th>
						                                            </tr>
						                                        </thead>
						                                        <tbody>
						                                        	<?php
																		for($a=0; $a < 3; $a++)
																		{
																			$b=$a+1;
																			echo'
																				<tr>
																					<td>
																						'.$b.'
																						<input type="hidden" name="id_image[]" value="'.$b.'">
																					</td>
																					<td valign="middle">
																						<input type="file" name="ImageUpload'.$b.'" id="imageUpload_'.$b.'" onchange="readURL_'.$b.'(this);"/>
																					</td>
																					<td>
																						<img id="blah_'.$b.'" class="img" src="http://placehold.it/80" alt="your image" />
																						<script>
																							function readURL_'.$b.'(input) {
																								if (input.files && input.files[0])
																								{
																									var reader = new FileReader();

																									reader.onload = function (e) {
																										$("#blah_'.$b.'")
																										.attr("src", e.target.result);
																									};
																									reader.readAsDataURL(input.files[0]);
																								}
																							}
																						</script>
																					</td>
																				</tr>
																			';
																		}
																	?>
						                                        </tbody>
						                                        <tfoot>
						                                            <tr>
						                                                <td colspan="3" valign="middle">
						                                                    <input type="submit" class="btn btn-info btn-fill pull-right save" value="Save" id="save" style="margin-top:10px;">
						                                                    <a href="<?php echo base_url();?>admin/transaction/workorder/<?php echo $menuid;?>" class="btn btn-danger pull-right" style="margin:10px 5px 0 0;">Cancel</a>
						                                                    <button type="reset" class="btn btn-default pull-right" style="margin:10px 5px 0 0;">Reset</button>
						                                                </td>
						                                            </tr>
						                                        </tfoot>
						                                   	</table>
						                                </div>
					                                </div>
					                         	</div>
					                  		</div>


					                    </div>
					              	</div>
				          		</div>
				            <!-- /.box-body -->
				        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <div id="snackbar" class="toast"></div>


	<div class="modal fade" id="finish-good-modal" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content finish-good-content" style="z-index:999">
			</div>
		</div>
	</div>
</div>s

    <?php $this->load->view('admin/master/footer_2');?>

    <?php
		for($a=0; $a < 20; $a++)
		{
			$b=$a+40;
			?>
            	<script>
					$(function () {
						$('#datepicker<?php echo $b;?>').datepicker({
						  autoclose: true
						});
					});
				</script>
            <?php
		}
	?>
