	<?php
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);
		$ID=$this->input->post('ID');

		$explode=explode('--', $ID);
		$ID=$explode[0];
		$code_supplier=$explode[1];
		$date_in=$explode[2];
		$requested=$explode[3];
		$price=$explode[4];

		setlocale(LC_ALL, 'id_ID.UTF-8');
		//echo $ID;
		//exit;


		$data_workorder_labour_detail=$this->master_model->select_in('ts_workorder_labour_detail','*',"WHERE id_workorder_labour=$ID");

		$count_wo_labour_detail=count($data_workorder_labour_detail);

		$sum_available = $this->master_model->select_in('ts_workorder_labour_detail','SUM(qty) AS total_available, SUM(subtotal) AS subtotal_available, SUM(paid) AS paid_total',"WHERE id_workorder_labour=$ID");

		$total_available=$sum_available[0]->total_available;
		$subtotal_available=$sum_available[0]->subtotal_available;
		$paid_total=$sum_available[0]->paid_total;


		$labour_available = $requested-$total_available;

		if($labour_available > 0 && $labour_available < $total_available)
		{
			$total_qty=$total_available;
		}else
		{
			$total_qty=$labour_available;
		}

		$menuid=$this->uri->segment(4);
		$id_workorder=$this->uri->segment(5);
		$count_loop = $this->uri->segment(6);
		// print_r($count_loop);
		// die();
    ?>

    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">
      	Request <?php echo $requested;?>, Available <?php echo $requested-$total_available;?>
      </h4>

      <input type="hidden" class="requested" value="<?php echo $requested;?>">
      <input type="hidden" class="retur" value="<?php echo $requested-$total_available;?>">
    </div>

    <!-- <form action="<?php echo base_url();?>admin/transaction/insert_wo_labour_detail/<?php echo $menuid.'/'.$id_workorder;?>" method="post"> -->
	<div class="modal-body">
		<div class="table-responsive">
			<table class="table table-bordered table-striped table-hover js-basic-example dataTable">
	            <thead>
	                <tr>
	                    <th>No</th>
	                    <th>Supplier</th>
	                    <th>Date</th>
	                    <th>Qty</th>
	                    <th>@cost</th>
	                    <th>Subtotal</th>
	                    <th>Paid</th>
	                    <th>Action</th>
						<!-- <?php
							if($count_loop == 'Yes')
							{
								echo'<th>In Inventory</th>';
							}
						?> -->
	                </tr>
	            </thead>

	            <tbody>
	            	<?php
	            		if($count_wo_labour_detail==0)
	            		{
	            			echo'
	            				<tr>
	            					<form action="'.base_url().'admin/transaction/insert_wo_labour_detail/'.$menuid.'/'.$id_workorder.'/'.$count_loop.'" method="post">
										<td>
											1
											<input type="hidden" name="id_workorder_labour" value="'.$ID.'" id="id_workorder_labour">
										</td>
										<td>
											<script>
				                                $(document).ready(function()
				                                {
				                                    $(".supplier_code").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").html(msg);
				                                             }
				                                        });
				                                    });
				                                });
				                            </script>
				                            <input type="text" name="supplier_code_labour" list="supplier_code" id="supplier_code_2" class="form-control supplier_code supplier_get_po_2" placeholder="Supplier Code" value="'.$code_supplier.'">
				                            <datalist id="supplier_code"></datalist>
										</td>
										<td>
											<input type="text" class="form-control date_in" name="date_in" id="datepicker200" value="'.date('m/d/Y').'">
										</td>
										<td>
											<script>
												$(document).ready(function()
												{
													$(".qty").focusout(function(e)
													{
														var qty = $(this).val();
														var price = $(".price").val();

														var length = document.getElementsByName("qty").length;

									   					var requested = $(".requested").val();
									   					var retur 	  = $(".retur").val();

									   					//alert(price);
														//return false;


									   					var available = 0;
									   					for(i=0; i < length; i++)
									   					{
									   						var qty = document.getElementsByName("qty")[i].value;

									   						var available=parseInt(available)+parseInt(qty);

									   					}



									   					if(available > requested)
														{
															var x = document.getElementById("snackbar")
															x.className = "show";
															x.innerHTML = "Qty should not be greather than total available!";
															setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

															$("#qty").val(retur);
															var subtotal =parseInt(retur)*parseFloat(price);

															$(".finish").val(retur);
														}else
														{
															var subtotal =parseInt(qty)*parseFloat(price);

															$(".finish").val(qty);
														}

														var subtotal=subtotal.toString().replace(/[.]/, ",");

														$(".subtotal").html(addCommas(subtotal));
														$("#subtotal").val(subtotal);



														$("#triger_click").trigger("click");
													});
												});
											</script>
											<input type="text" class="form-control qty" name="qty" value="'.$requested.'" id="qty">
										</td>
										<td>
											<script>
													$(".price").focusout(function(e)
													{
														var price = $(this).val();
														var qty = $("#qty").val();

														var subtotal=parseInt(qty)*parseFloat(price);

														var subtotal=subtotal.toString().replace(/[.]/, ",");

														//alert(subtotal);
														//return false;

														$(".subtotal").html(addCommas(subtotal));
														$("#subtotal").val(subtotal);

														$("#triger_click").trigger("click");
													});
												
											</script>
											<input type="text" class="form-control price" name="price" value="0" id="price">
										</td>
										<td style="font-weight:bold" class="subtotal">
											0
										</td>
										<td>
											0
										</td>
										<td style="text-align:center">
											<input type="hidden" name="subtotal" id="subtotal">

											<script>
							                    $("#overlay").hide();

							                    $("#save_process").on("click", function()
							                    {
							                    	var length = document.getElementsByName("qty").length;

							                    	//alert(length);
							                    	//return false;

								   					var requested = $(".requested").val();

								   					var available = 0;
								   					for(i=0; i < length; i++)
								   					{
								   						var qty = document.getElementsByName("qty")[i].value;

								   						var available=parseInt(available)+parseInt(qty);

								   					}

													if(available > requested)
													{
														var x = document.getElementById("snackbar")
														x.className = "show";
														x.innerHTML = "Qty should not be greather than total available!";
														setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

														$("#qty").val(0);
														$("#price").val(0);
														$(".subtotal").html(0);
													}else
													{
									                      $("#overlay").show();

									                      var id_workorder_labour = $("#id_workorder_labour").val();
									                      var supplier = $(".supplier_get_po_2").val();
									                      var date     = $(".date_in").val();
									                      var qty      = $("#qty").val();
									                      var price    = $("#price").val();

									                      if(supplier == 0 || supplier == "")
									                      {
									                      	var x = document.getElementById("snackbar")
															x.className = "show";
															x.innerHTML = "Supplier cannot be empty!";
															setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

															$("#overlay").hide();
									                      	return false;
									                      }

									                      if(qty == 0 || qty == "")
									                      {
									                      	var x = document.getElementById("snackbar")
															x.className = "show";
															x.innerHTML = "Qty cannot be empty!";
															setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

															$("#overlay").hide();
									                      	return false;
									                      }

									                      if(price == 0 || price == "")
									                      {
									                      	var x = document.getElementById("snackbar")
															x.className = "show";
															x.innerHTML = "Price cannot be empty!";
															setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

															$("#overlay").hide();
									                      	return false;
									                      }

									                      var ID 	   = id_workorder_labour+"--"+supplier+"--"+date+"--"+qty+"--"+price;

									                      //alert(date);
									                      //return false;

									                      $.ajax({
									                         type: "POST",
													 		 dataType: "html",
									                         url: "'.base_url().'admin/transaction/insert_wo_labour_detail/'.$menuid.'/'.$id_workorder.'/'.$count_loop.'",
									                         data:"ID="+ID,
									                         success: function(msg)
									                         {
									                            $("#overlay-body").html(msg);
									                            $("#overlay").hide();

									                              window.location.assign("'.base_url().'admin/transaction/production_insert/'.$menuid.'/'.$id_workorder.'");
									                         }
									                      });

									                  }

							                    });
							                </script>

			                                <button type="submit" class="btn btn-primary btn-fill pull-right" id="save_process">
			                                	Save
			                                </button>
										</td>
										';
											if($count_loop == 'Yes')
											{
												echo'
													<td style="text-align: center">
													</td>
												';
											}
										echo'

								</tr>
	            			';
	            		}else
	            		{
		            		for($a=0; $a < count($data_workorder_labour_detail); $a++)
		            		{
		            			$id_wo_labour_detail=$data_workorder_labour_detail[$a]->ID;
		            			$b=$a+1;
		            			echo'
			            			<tr>
			            				<td>
			            					'.$b.'
			            					<input type="hidden" name="id_workorder_labour" value="'.$ID.'" id="id_workorder_labour_'.$b.'">
			            				</td>
			            				<td>
			            					'.$data_workorder_labour_detail[$a]->code_supplier.'
			            					<input type="hidden" class="supplier_get_po_2_'.$b.'" value="'.$data_workorder_labour_detail[$a]->code_supplier.'">
			            				</td>
			            				<td>
			            					'.date('d M Y', strtotime($data_workorder_labour_detail[$a]->date_done)).'
			            					<input type="hidden" class="date_in_'.$b.'" value="'.$data_workorder_labour_detail[$a]->date_done.'">
			            				</td>
			            				<td>
			            					'.$data_workorder_labour_detail[$a]->qty.'
			            					<input type="hidden" class="form-control qty_'.$b.'" name="qty" value="'.$data_workorder_labour_detail[$a]->qty.'" id="qty_'.$b.'">
			            				</td>
			            				<td>
			            					'.money_format('%.2n', $data_workorder_labour_detail[$a]->price). "\n".'
			            					<input type="hidden" class="form-control price_'.$b.'" name="price" value="'.$data_workorder_labour_detail[$a]->price.'" id="price_'.$b.'">
			            				</td>
			            				<td style="font-weight:bold">
											'.money_format('%.2n', $data_workorder_labour_detail[$a]->subtotal). "\n".'
										</td>
										<td style="font-weight:bold">
											'.money_format('%.2n', $data_workorder_labour_detail[$a]->paid). "\n".'
										</td>
			            				<td style="text-align:center">
			            					<script>
							                  $(document).ready(function()
							                  {
							                    
							                  });

							                  $("#overlay").hide();

							                    $("#delete_process_'.$b.'").on("click", function()
							                    {
							                    	var length = document.getElementsByName("qty").length;

							                      $("#overlay").show();

							                      var id_workorder_labour = $("#id_workorder_labour_'.$b.'").val();
							                      var supplier = $(".supplier_get_po_2_'.$b.'").val();
							                      var date     = $(".date_in_'.$b.'").val();
							                      var qty      = $("#qty_'.$b.'").val();
							                      var price    = $(".price_'.$b.'").val();

							                      var ID 	   = id_workorder_labour+"--"+supplier+"--"+date+"--"+qty+"--"+price;

							                      //alert(ID);
							                      //return false;

							                      $.ajax({
							                         type: "POST",
											 		 dataType: "html",
							                         url: "'.base_url().'admin/transaction/delete_labour_detail/'.$menuid.'/'.$id_workorder.'/'.$ID.'/'.$id_wo_labour_detail.'",
							                         data:"ID="+ID,
							                         success: function(msg)
							                         {
							                            $("#overlay-body").html(msg);
							                            $("#overlay").hide();

							                            window.location.assign("'.base_url().'admin/transaction/production_insert/'.$menuid.'/'.$id_workorder.'");
							                         }
							                      });
							                    });
							                </script>

							                ';
							                	if($data_workorder_labour_detail[$a]->subtotal == $data_workorder_labour_detail[$a]->paid)
							                	{
							                		 if($data_workorder_labour_detail[$a]->id_jurnal_workorder_labour == "0"){?>
							                			 <a href="<?php echo base_url();?>api/data_labour_jurnal/<?php echo $ID.'/'.$id_workorder.'/'.$id_wo_labour_detail;?>" class="btn btn-danger pull-right" style="cursor: pointer" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i>"> </style>
						                                  send to Jurnal1
						                                </a>
							                		<?}
							                		echo'<a href="https://my.jurnal.id/purchases/'.$data_workorder_labour_detail[$a]->id_jurnal_workorder_labour.'">
						                                    #'.$data_workorder_labour_detail[$a]->id_jurnal_workorder_labour.'
						                                </a>';
							                	}else
							                	{
							                		

							                		$response=$this->master_model->get_id_jurnal($data_workorder_labour_detail[$a]->id_jurnal_workorder_labour);

							                		// print_r($response->data);
							                		if($response->data == "tidak ditemukan"){?>
							                				<a href="<?php echo base_url();?>api/data_labour_jurnal/<?php echo $ID.'/'.$id_workorder.'/'.$id_wo_labour_detail;?>" class="btn btn-danger pull-right" style="cursor: pointer" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i>"> </style>
						                                  Send to Jurnal
						                                </a>
							                		<?}else{?>
							                			<a href="<?php echo base_url();?>api/data_labour_jurnal/<?php echo $ID.'/'.$id_workorder.'/'.$id_wo_labour_detail;?>" class="btn btn-success pull-right" style="cursor: pointer" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i>"> </style>
						                                  Send to Jurnal2
						                                </a>
							                		<?}

							                		if($data_workorder_labour_detail[$a]->id_jurnal_workorder_labour != "0"){?>
							                			 
							                		<?}
							                		if($data_workorder_labour_detail[$a]->id_jurnal_workorder_labour == "0"){?>
							                			 <a href="<?php echo base_url();?>api/data_labour_jurnal/<?php echo $ID.'/'.$id_workorder.'/'.$id_wo_labour_detail;?>" class="btn btn-success pull-right" style="cursor: pointer" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i>"> </style>
						                                  Send to Jurnal
						                                </a>
							                		<?}
							                		echo'
							                			<a style="cursor:pointer" class="text-red" id="delete_process_'.$b.'">
						                                    <i class="fa fa-trash-o"></i>
						                                </a> &nbsp;<a href="https://my.jurnal.id/purchases/'.$data_workorder_labour_detail[$a]->id_jurnal_workorder_labour.'" target="_blank">
						                                    #'.$data_workorder_labour_detail[$a]->id_jurnal_workorder_labour.'
						                                </a>
							                		';
							                	}
							                echo'
			            				</td>
													';
														if($count_loop == 'Yes')
														{
															echo'
																<td style="text-align: center">
																	';
																		if($data_workorder_labour_detail[$a]->inventory_status == 1)
																		{
																			echo '
																				<i class="fa fa-check text-green"></i>
																				<br/>
																				'.date('d M Y', strtotime($data_workorder_labour_detail[$a]->inventory_input_date)).'
																			';
																		}else {
																			echo '';
																		}
																	echo'
																</td>
															';
														}
													echo'
			            			</tr>
			            		';
		            		}
		            	}

		            	if($requested == $total_available || $total_available == 0)
						{
							$display = 'style="display:none"';
						}else
						{
							$display = '';
						}


	            		for($r=0; $r < 1; $r++)
						{
							$s=$r+1;

							$d=$r+201;

							$t = $s + $count_wo_labour_detail;
							echo'
								<tr id="row5'.$s.'" '.$display.'>
									<td>
										'.$t.'
										<input type="hidden" name="id_workorder_labour" value="'.$ID.'" id="id_workorder_labour_2">
									</td>
									<td>
										<script>
			                                $(document).ready(function()
			                                {
			                                    $(".supplier_code2").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_code2").html(msg);
			                                             }
			                                        });
			                                    });
			                                });
			                            </script>
			                            <input type="text" name="supplier_code_labour" list="supplier_code2" id="supplier_code_pop_2" class="form-control supplier_code2 supplier_get_po_2'.$s.'" placeholder="Supplier Code" value="'.$code_supplier.'">
			                            <datalist id="supplier_code2"></datalist>
									</td>
									<td>
										<input type="text" class="form-control date_in_200" name="date_in" id="datepicker202" value="'.date('m/d/Y').'">
									</td>
									<td>
										<script>
											$(document).ready(function()
											{
												$(".qty_2").focusout(function(e)
												{
													var qty = $(this).val();
													var price = $("#price_pop_2").val();

													var length = document.getElementsByName("qty").length;

								   					var requested = $(".requested").val();
								   					var retur 	  = $(".retur").val();

								   					var available = 0;
								   					for(i=0; i < length; i++)
								   					{
								   						var qty = document.getElementsByName("qty")[i].value;

								   						var available=parseInt(available)+parseInt(qty);

								   					}

								   					if(available > requested)
													{
														var x = document.getElementById("snackbar")
														x.className = "show";
														x.innerHTML = "Qty should not be greather than total available!";
														setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

														$("#qty_pop_2").val(retur);
														var subtotal =parseInt(retur)*parseFloat(price);

														$(".finish").val(retur);
													}else
													{
														var subtotal =parseInt(qty)*parseFloat(price);

														$(".finish").val(qty);
													}

													//var subtotal=parseInt(qty)*parseFloat(price);

													var subtotal=subtotal.toString().replace(/[.]/, ",");

													$(".subtotal_2").html(addCommas(subtotal));
													$("#subtotal_2").val(subtotal);

													$("#triger_click").trigger("click");
												});
											});
										</script>
										<input type="text" class="form-control qty_2" name="qty" value="0" id="qty_pop_2">
									</td>
									<td>
										<script>
											$(document).ready(function()
											{
												$(".price_2").focusout(function(e)
												{
													var price = $(this).val();
													var qty = $("#qty_pop_2").val();

													var subtotal=parseInt(qty)*parseInt(price);

													$(".subtotal_2").html(addCommas(subtotal));
													$("#subtotal_2").val(subtotal);
												});
											});
										</script>

										<input type="text" class="form-control price_2" name="price" value="'.$price.'" id="price_pop_2">
									</td>
									<td style="font-weight:bold" class="subtotal_2">
										0
									</td>
									<td>
										0
									</td>
									<td style="text-align:center">
										<input type="hidden" name="subtotal" id="subtotal_2">

										<script>
						                  
						                    $("#overlay").hide();

						                    $("#save_process_2").on("click", function()
						                    {

						                    	var length = document.getElementsByName("qty").length;

						                    	//alert(length);
						                    	//return false;
						                    	//fagafgafgafga
							   					var requested = $(".requested").val();

							   					var available = 0;
							   					for(i=0; i < length; i++)
							   					{
							   						var qty = document.getElementsByName("qty")[i].value;

							   						var available=parseInt(available)+parseInt(qty);

							   					}

												if(available > requested)
												{
													var x = document.getElementById("snackbar")
													x.className = "show";
													x.innerHTML = "Qty should not be greather than total available!";
													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

													$("#qty_pop_2").val(0);
													$("#price_pop_2").val(0);
													$(".subtotal_2").html(0);
												}else
												{
													$("#overlay").show();

								                      var id_workorder_labour = $("#id_workorder_labour_2").val();
								                      var supplier = $("#supplier_code_pop_2").val();
								                      var date     = $(".date_in_200").val();
								                      var qty      = $("#qty_pop_2").val();
								                      var price    = $("#price_pop_2").val();

								                      if(supplier == 0 || supplier == "")
								                      {
								                      	var x = document.getElementById("snackbar")
														x.className = "show";
														x.innerHTML = "Supplier cannot be empty!";
														setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

														$("#overlay").hide();
								                      	return false;
								                      }

								                      if(qty == 0 || qty == "")
								                      {
								                      	var x = document.getElementById("snackbar")
														x.className = "show";
														x.innerHTML = "Qty cannot be empty!";
														setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

														$("#overlay").hide();
								                      	return false;
								                      }

								                      if(price == 0 || price == "")
								                      {
								                      	var x = document.getElementById("snackbar")
														x.className = "show";
														x.innerHTML = "Price cannot be empty!";
														setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

														$("#overlay").hide();
								                      	return false;
								                      }

								                      var ID 	   = id_workorder_labour+"--"+supplier+"--"+date+"--"+qty+"--"+price;

								                      //alert(ID);
								                      //return false;

								                      $.ajax({
								                         type: "POST",
												 		 dataType: "html",
								                         url: "'.base_url().'admin/transaction/insert_wo_labour_detail/'.$menuid.'/'.$id_workorder.'",
								                         data:"ID="+ID,
								                         success: function(msg)
								                         {
								                            $("#overlay-body").html(msg);
								                            $("#overlay").hide();

								                             window.location.assign("'.base_url().'admin/transaction/production_insert/'.$menuid.'/'.$id_workorder.'");
								                         }
								                      });
												}
						                    
						                  });
						                </script>

		                                <button type="submit" class="btn btn-primary btn-fill pull-right" id="save_process_2">
		                                	Save
		                                </button>
									</td>
									';
										if($count_loop == 'Yes')
										{
											echo'
												<td style="text-align: center">
												</td>
											';
										}
									echo'
								</tr>
							';
						}

	            	?>
	            </tbody>
	            <tfoot>
	                <tr>
	                    <td colspan="3">
	                    	<?php
	                    		if($labour_available==0)
								{
									echo'';
								}else
								{
									?>
										<!-- <a class="btn btn-primary addOption2 loading_btn" onClick="clickME()" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing">
				                            Add Row
				                        </a> -->
									<?php
								}
	                    	?>

	                        <script>
	                            $('.loading_btn').on('click', function()
	                            {
	                                var $this = $(this);
	                                $this.button('loading');
	                                setTimeout(function()
	                                {
	                                   $this.button('reset');
	                                }, 500);
	                            });
	                        </script>

	                        <?php
	                        	if($count_wo_labour_detail==0)
	            				{
	            					$count_wo_labour_detail=1;
	            				}else
	            				{
	            					$count_wo_labour_detail=$count_wo_labour_detail;
	            				}
	                        ?>
	                        <script>
	                            $(document).ready(function()
	                            {
	                                var inc = <?php echo $count_wo_labour_detail;?>;
	                                $(".addOption2").on('click',function()
	                                {
	                                    inc=inc+1;
	                                    $("#row5"+inc+"").show();
	                                });
	                            });
	                        </script>

	                        Total :
	            		</td>
	            		<td>
	            			<span id="total" style="font-weight: bold;"><?php echo $total_available;?></span>
	            		</td>
	            		<td>

	            		</td>
	            		<td>
	            			<span id="total" style="font-weight: bold;">
	            				<?php echo money_format('%.2n', $subtotal_available). "\n";?>
	            			</span>
	            		</td>
	            		<td colspan="2" style="text-align: left;">
	            			<span id="total" style="font-weight: bold;">
	            				<?php echo money_format('%.2n', $paid_total). "\n";?>
	            			</span>
	            		</td>
	                </tr>
	            </tfoot>
	        </table>
	       </div>
       </div>

       <div class="overlay" id="overlay">
	    <i class="fa fa-refresh fa-spin"></i>
	  </div>

       <div class="modal-footer">
       		<a id="triger_click" style="display: none" class="trigger">click</a>
       		<script>
       			$(document).ready(function()
   				{
   					$(".trigger").on('click',function()
	                {
	   					var length = document.getElementsByName("qty").length;

	   					var requested = $(".requested").val();

	   					var available = 0;
	   					for(i=0; i < length; i++)
	   					{
	   						var qty = document.getElementsByName("qty")[i].value;

	   						var available=parseInt(available)+parseInt(qty);

	   						//alert(available);
	   					}

						if(available > requested)
						{
							var x = document.getElementById("snackbar")
							x.className = "show";
							x.innerHTML = "Qty should not be greather than total available!";
							setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

							//$("#qty_pop_"+i).val(0);

							$("#total").html(requested);
						}else
						{
							$("#total").html(available);
						}
   					});
   				});
       		</script>

       		<!--
			<input type="button" class="btn btn-danger btn-fill pull-right save" value="Close" >

            <button type="reset" class="btn btn-default pull-right reset" style="margin:0 5px 0 0;">Reset</button>
-->
       </div>
       <!-- </form>  -->

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