<?php 
    $this->load->view('admin/master/header_2');
	$modul=$this->uri->segment(3);
	$menuid=$this->uri->segment(4);
?>

<!--<link href="<?php echo base_url();?>assets/css/light-bootstrap-dashboard.css" rel="stylesheet"/>-->

<div class="content-wrapper">
    <section class="content-header">
        <h1>Insert Purchase
            <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/purchase/<?php echo $menuid;?>">Purchase</a></li>
            <li class="active">Insert Purchase</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 box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">Insert</h3>
                            <hr>
                            <form action="<?php echo base_url();?>admin/transaction/insert_purchase/<?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>Purchase Order No *</label>
								                        <?php
															$po=$this->master_model->po();
														?>
						                        	<input type="text" name="purchase" class="form-control" placeholder="Purchase Order No" readonly="readonly" required="required" value="<?php echo $po;?>">
						                    	</div>
						                    </div>		                    
						                    <div class="form-group">
						                    	<div class="form-line">
							                        <label>Date</label>
								                        <?php
															$today=strtotime(date('Y-m-d'));
															$today=date('m/d/Y', $today);
														?>
						                        	<input type="text" name="date" id="datepicker" class="form-control" placeholder="Date" value="<?php echo $today;?>">
						                    	</div>
						                    	<script type="text/javascript">
													$(function(){
														    $("#datepicker").datepicker();
														});
										        </script>
						                    </div>    
						                    <div class="form-group">
						                    	<div class="form-line">
							                        <label>Required Date</label>
								                        <?php
															$until=strtotime(date('Y-m-d'));
															$until=strtotime('+30 day', $until);
															$until=date('m/d/Y', $until);
														?>
							                        <input type="text" name="required_date" id="datepicker2" class="form-control" placeholder="Required Date" value="<?php echo $until;?>">
						                    	</div>
						                    	<script type="text/javascript">
													$(function(){
														    $("#datepicker2").datepicker();
														});
										        </script>
						                    </div>
						                </div>
					                	<div class="col-md-4">
						                    <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_supplier/<?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/supplier_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 class="form-line">
						                        	<label>Supplier</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 tes" 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 Supplier</option>
											              <?php foreach ($supplier as $key => $value): ?>
											              		<option value="<?php echo $value->ID ?>">
											                      <?php echo $value->code.' - '.$value->name; ?>
											                    </option>
											              <?php endforeach ?>
											              
											        </select>
						                        </div>
						                    </div>
					                    	<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_supplier_2/<?php echo $menuid;?>",
																 data:"name="+name,
																 success: function(msg)
																 {
																	$("#supplier_name").html(msg);
																 }
															}); 				  
														});
														
														$(".tes_2").focusout(function(e)
														{
															var name = $(this).val();
															
															$.ajax({
																 type: "POST",
																 dataType: "html",
																 url: "<?php echo base_url();?>admin/transaction/tes_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>Supplier 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 tes_2" placeholder="Supplier Name" required="required">
					                        			<datalist id="supplier_name"></datalist>
					                    		</div> -->
					                    	</div>
					                		<div class="form-group">
					                			<div class="form-line">
					                        		<label>Payment Terms</label>
														<?php
															$today=date('Y-m-d');
															$today=date('m/d/Y', strtotime($today));
														?>
					                        		<input type="text" name="payment_term" class="form-control payment_terms" placeholder="Days">
					                    		</div>
					                    	</div>
					                    	<div class="form-group">
					                    		<div class="form-line">
					                        		<label>PPN :</label>
					                        		
					                        		<input type="text" name="status" class="form-control st" value=""readonly="readonly">
					                    		</div>
					                    	</div>
					                	</div>
					                	<div class="col-md-4">    
					                    	<div class="form-group">
					                    		<div class="form-line">
					                        		<label>Ship Via</label>
					                        			<input type="text" name="ship_via" class="form-control phone" placeholder="Ship Via">
					                    		</div>
					                    	</div>          
					                    	<div class="form-group">
												<script type="text/javascript">
													$(document).ready(function()
													{
														exist2 = 0;
														$("#ref").change(function (e)
														{
															var code = $(this).val();
															$("#code-result").show();
															$.ajax({
																 type:"POST",
																 url: "<?php echo base_url();?>admin/master/check_code_supplier",
																 data:"code="+code,
																 success:function(msg)
																 {
																	 if(msg == 1)
																	 {
																		 exist2 = 1;
																		 $("#code-result").html('<font style="color:#FF024F"><i class="fa fa-times"></i> Number already in use</font>');
																	 }else if(msg==0)
																	 {
																		 exist2 = 0;
																		 $("#code-result").html('<font style="color:#2BB0EA"><i class="fa fa-check" style="color:#2DBE00"></i> Number not in use</font>');
																	 }else if(msg==2)
																	 {
																		 exist2 = 2;
																		 $("#code-result").html('');
																	 }
																 }
															});
														});
														
														$(".save").click(function()
														{
															if(exist2 == 1)
															{
																alert('Number already in use');
																return false;
															}else
															{
																return true;
															}
														});
														
													});
												</script>
												<div class="form-line">
					                        		<label>Ref. No</label>
														<span id="code-result" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
					                        		<input type="text" name="ref_no" class="form-control" placeholder="Ref. No">
					                    		</div>
					                    	</div>
					                    	<div class="form-group">
					                    		<div class="form-line">
					                        		<label>Status</label>
					                        		<br />
					                        		<input type="text" name="status" class="form-control" value="Pending"readonly="readonly">
					                    		</div>
					                    	</div>

					                    	
					                	</div>
					              	</div>				              
						            
						            	<div class="table-responsive">
						            		<table class="table table-bordered table-striped table-hover dataTable">  
							                    <thead>
							                        <tr>
							                            <th>No.</th>
							                            <th>Code</th>
							                            <th>Item</th>
							                            <th>Qty</th>
							                            <th>In Qty</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_detail_<?php echo $d;?>").focusout(function(e)
							                                            {
							                                                var code = $(this).val();
							                                                var supplier = $("#supplier_code_2").val();
																			
																			if(supplier == '')
																			{
																				var x = document.getElementById("snackbar")
																				x.className = "show";
																				x.innerHTML = "Please choose supplier first!";
																				setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000); 
																				
																				$("#supplier_code_2").focus();
																				$("#inventory_codes_<?php echo $d;?>").val('');
																			}else
																			{
																				$.ajax({
																					 type: "POST",
																					 dataType: "html",
																					 url: "<?php echo base_url();?>admin/transaction/inventory_get_detail/<?php echo $menuid;?>/"+supplier,
																					 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 qty  			 = explode[1];
																							var price  		   = explode[2];
																							var check   		   = explode[3];
																							
																							if(check=='exist')
																							{
																								$("#inventory_names_<?php echo $d;?>").val(inventory_name);
																								$(".inventory_prices_<?php echo $d;?>").val(price);
																								$("#qty_<?php echo $d;?>").val(qty);
																							}else
																							{
																								$("#inventory_names_<?php echo $d;?>").val('');
																								$("#qty_<?php echo $d;?>").val(0);
																								
																								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[]" 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;?>" style="width:100px" <?php echo $required;?>/>
							                                    <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/<?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 qty  			 = explode[1];
							                                                            var check   		   = explode[2];
							                                                            
							                                                            if(check=='exist')
							                                                            {
							                                                                $("#inventory_codes_<?php echo $d;?>").val(inventory_code);
							                                                                $("#qty_<?php echo $d;?>").val(qty);
							                                                            }else
							                                                            {
							                                                                $("#inventory_codes_<?php echo $d;?>").val('');
							                                                                $("#qty_<?php echo $d;?>").val(0);
							                                                                
							                                                                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[]" 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;?>" style="width:250px"/>
							                                    <datalist id="inventory_name_<?php echo $d;?>"></datalist>
							                                </td>
							                                <td>
							                                    <script>
							                                        $(document).ready(function()
							                                        {
							                                            $(".qty_subtotal_<?php echo $d;?>").focusout(function(e)
							                                            {
							                                                var qty = $(this).val();
							                                                var price = $("#price_<?php echo $d;?>").val();
																			
																			qty=qty.replace(/,/g , '.');
																			
							                                                $.ajax({
							                                                     type: "POST",
							                                                     dataType: "html",
							                                                     url: "<?php echo base_url();?>admin/transaction/qty_subtotal/"+price+"/<?php echo $menuid;?>",
							                                                     data:"qty="+qty,
							                                                     success: function(msg)
							                                                     {
																					$("#qty_<?php echo $d;?>").val(qty);
							                                                        $(".subtotal_<?php echo $d;?>").html(msg);
							                                                     }
							                                                }); 		
							                                            });
							                                        });
							                                    </script>
							                                    <input type="text" name="qty[]" id="qty_<?php echo $d;?>" style="width:70px; float:left" class="form-control qty_subtotal_<?php echo $d;?>" value="0"/>
							                                </td>
							                                <td align="center">
							                                    0
							                                </td>
							                                <td>
							                                    <script>
							                                        $(document).ready(function()
							                                        {
							                                            $(".price_subtotal_<?php echo $d;?>").focusout(function(e)
							                                            {
							                                                var price = $(this).val();
							                                                var qty = $("#qty_<?php echo $d;?>").val();
							                                                
							                                                $.ajax({
							                                                     type: "POST",
							                                                     dataType: "html",
							                                                     url: "<?php echo base_url();?>admin/transaction/price_subtotal/"+qty+"/<?php echo $menuid;?>",
							                                                     data:"price="+price,
							                                                     success: function(msg)
							                                                     {
							                                                        $(".subtotal_<?php echo $d;?>").html(msg);
							                                                     }
							                                                }); 		
							                                            });
							                                        });
							                                    </script>
							                                    <input type="text" name="price[]" id="price_<?php echo $d;?>" style="width:80px;" class="form-control price_subtotal_<?php echo $d;?> inventory_prices_<?php echo $d;?>" placeholder="Price" value="0"/>
							                                </td>
							                                <td align="center" class="subtotal_<?php echo $d;?>">
							                                    0
							                                    <input type="hidden" name="subtotal[]" style="width:80px;" class="form-control" placeholder="Subtotal"/>
							                                </td>
							                                <td style="text-align:center">
							                                    <script>
							                                        $(document).ready(function()
							                                        {
							                                            $(".delete_<?php echo $d;?>").click(function(e)
							                                            {
							                                                $("#inventory_codes_<?php echo $d;?>").val('');
							                                                $("#qty_<?php echo $d;?>").val(0);
							                                                $("#inventory_names_<?php echo $d;?>").val('');
							                                                $("#price_<?php echo $d;?>").val(0);
							                                                $(".subtotal_<?php echo $d;?>").html('0 <input type="hidden" name="subtotal[]" style="width:80px;" class="form-control" placeholder="Subtotal"/>');
							                                                                
							                                                var x = document.getElementById("snackbar")
							                                                x.className = "show";
																			x.innerHTML = "Item has been deleted!";
							                                                setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
							                                                
							                                                
							                                            });
							                                        });
							                                    </script>
							                                    <a alt="1" class="text-red delete_<?php echo $d;?>" style="cursor:pointer">
							                                        <i class="fa fa-trash-o"></i>
							                                    </a>
							                                </td>
							                            </tr>
							                        <?php } ?>
							                        
							                        
							                        <?php
														for($a=0; $a < 5; $a++)
														{
															$b=$a+6;
													?>
							                        	<tr id="row2<?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_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/<?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 qty  			 = explode[1];
																					var check   		   = explode[2];
																					
																					if(check=='exist')
																					{
																						$("#inventory_names_<?php echo $b;?>").val(inventory_name);
																						$("#qty_<?php echo $b;?>").val(qty);
																					}else
																					{
																						$("#inventory_names_<?php echo $b;?>").val('');
																						$("#qty_<?php echo $b;?>").val(0);
																						
																						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[]" 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;?>" style="width:100px"/>
							                                <datalist id="inventory_code_<?php echo $b;?>"></datalist>
							                                </td>
							                                <td>
							                                    <script>
																	$(document).ready(function()
																	{
																		$(".inventory_name_<?php echo $b;?>").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 $b;?>").html(msg);
																				 }
																			}); 				  
																		});
																		
																		
																		$(".inventory_name_get_detail_<?php echo $b;?>").focusout(function(e)
																		{
																			var name = $(this).val();
																			
																			$.ajax({
																				 type: "POST",
																				 dataType: "html",
																				 url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail/<?php echo $menuid;?>",
																				 data:"name="+name,
																				 success: function(msg)
																				 {
																					if(name=='')
																					{
																						$("#inventory_codes_<?php echo $b;?>").val('');
																						$("#qty_<?php echo $b;?>").val(0);
																					}else
																					{
																						var data_inventory = msg;
																						var explode = data_inventory.split("%");
																						
																						var inventory_code  = explode[0];
																						var qty  			 = explode[1];
																						var check   		   = explode[2];
																						
																						if(check=='exist')
																						{
																							$("#inventory_codes_<?php echo $b;?>").val(inventory_code);
																							$("#qty_<?php echo $b;?>").val(qty);
																						}else
																						{
																							$("#inventory_codes_<?php echo $b;?>").val('');
																							$("#qty_<?php echo $b;?>").val(0);
																							
																							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[]" 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;?>" style="width:250px"/>
																<datalist id="inventory_name_<?php echo $b;?>"></datalist>
							                                </td>
							                                <td>
																<script>
							                                        $(document).ready(function()
							                                        {
							                                            $(".qty_subtotal_<?php echo $b;?>").focusout(function(e)
							                                            {
							                                                var qty = $(this).val();
							                                                var price = $("#price_<?php echo $b;?>").val();
							                                                
							                                                qty=qty.replace(/,/g , '.');
																			
							                                                $.ajax({
							                                                     type: "POST",
							                                                     dataType: "html",
							                                                     url: "<?php echo base_url();?>admin/transaction/qty_subtotal/"+price+"/<?php echo $menuid;?>",
							                                                     data:"qty="+qty,
							                                                     success: function(msg)
							                                                     {
																					$("#qty_<?php echo $d;?>").val(qty);
							                                                        $(".subtotal_<?php echo $d;?>").html(msg);
							                                                     }
							                                                }); 		
							                                            });
							                                        });
							                                    </script>
							                                    <input type="text" name="qty[]" id="qty_<?php echo $b;?>" style="width:70px; float:left" class="form-control qty_subtotal_<?php echo $b;?>" value="0"/>
							                                </td>
							                                
							                                <td align="center" class="subtotal_<?php echo $b;?>">
							                                    0
							                                    <input type="hidden" name="subtotal[]" style="width:80px;" class="form-control" placeholder="Subtotal"/>
							                                </td>

							                                <td>
							                                    <script>
							                                        $(document).ready(function()
							                                        {
							                                            $(".price_subtotal_<?php echo $b;?>").focusout(function(e)
							                                            {
							                                                var price = $(this).val();
							                                                var qty = $("#qty_<?php echo $b;?>").val();
							                                                
							                                                $.ajax({
							                                                     type: "POST",
							                                                     dataType: "html",
							                                                     url: "<?php echo base_url();?>admin/transaction/price_subtotal/"+qty+"/<?php echo $menuid;?>",
							                                                     data:"price="+price,
							                                                     success: function(msg)
							                                                     {
							                                                        $(".subtotal_<?php echo $b;?>").html(msg);
							                                                     }
							                                                }); 		
							                                            });
							                                        });
							                                    </script>
							                                    <input type="text" name="price[]" id="price_<?php echo $b;?>" style="width:80px;" class="form-control price_subtotal_<?php echo $b;?>" placeholder="Price" value="0"/>
							                                </td>
							                                
							                                <td align="center">
							                                    0
							                                </td>
							                                <td style="text-align:center">
							                                    <script>
																	$(document).ready(function()
																	{
																		$(".delete_<?php echo $b;?>").click(function(e)
																		{
																			$("#inventory_codes_<?php echo $b;?>").val('');
																			$("#qty_<?php echo $b;?>").val(0);
																			$("#inventory_names_<?php echo $b;?>").val('');
																			$("#price_<?php echo $b;?>").val(0);
																			$(".subtotal_<?php echo $b;?>").html('0 <input type="hidden" name="subtotal[]" style="width:80px;" class="form-control" placeholder="Subtotal"/>');
																							
																			var x = document.getElementById("snackbar")
																			x.className = "show";
																			x.innerHTML = "Fill is empty!";
																			setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																			
																			$(this).closest("tr").remove();
																		});
																	});
																</script>
																<a alt="<?php echo $b;?>" class="text-red delete_<?php echo $b;?>" style="cursor:pointer">
																	<i class="fa fa-trash-o"></i>
																</a>
							                                </td>
							                            </tr>	
							                        <?php } ?>
							                        
							                    </tbody>
							                    <tfoot>
							                    	<tr>
							                        	<td colspan="9">
							                            	<a class="btn btn-primary addOption loading_btn" onClick="clickME()" id="addRow" 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;
							                                            $("#row2"+inc+"").show();
							                                        });
							                                    });
							                                </script>
							                            </td>
							                            
							                        </tr>
							                        <tr>
							                        	<td colspan="3">
							                            	<strong>Note : </strong>
							                                <input name="note" type="text" class="form-control" />
							                            </td>
							                        	<td colspan="6" valign="middle">
							                            	<button type="submit" class="btn btn-info btn-fill pull-right" id="save" style="margin-top:10px;">Save</button>
							                                <a href="<?php echo base_url();?>admin/transaction/purchase/<?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>
					            <!-- /.box-body -->
					            
					            
					        </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<div id="snackbar"></div>


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