<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_file);	?>
<!-- BEGIN: Content-->
<div class="app-content content">
    <div class="content-overlay"></div>
    <div class="content-wrapper">
        <div class="content-header row">
            <div class="content-header-left col-md-12 col-12 mb-2 breadcrumb-new">
                <h3 class="content-header-title mb-0 d-inline-block"><?php echo $sub_ModuleName;?></h3>
                <div class="row breadcrumbs-top d-inline-block float-right">
                    <div class="breadcrumb-wrapper col-12">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?php echo site_url('User/dashboard');?>">Home</a></li>
                            <li class="breadcrumb-item"><a href="#"><?php echo $moduleName;?></a></li>
                            <li class="breadcrumb-item active"><?php echo $sub_ModuleName;?></li>
                        </ol>
                    </div>
                </div>
            </div> 
        </div>
        <div class="content-body"><!-- Basic form layout section start -->
			<section id="basic-form-layouts">
				<form class="form" autocomplete="off" action="<?php echo site_url('Eshanya/addProduction');?>" method="post">
					<div class="row justify-content-md-center">
						<div class="col-md-12">		    
							<div class="card" style="height: auto!important;">				
								<div class="card-content collapse show">
									<div class="card-body">						
										<div class="row justify-content-md-center card_margin">
											<div class="col-md-4 mleft">
												<div class="form-body">
													<div class="form-group">
													<?php 
														$cur_date = date("d-m-Y"); 
														$branch_id = $_SESSION['branch_id'];
														$branch_name = $_SESSION['branch_name'];
														$full_name = $_SESSION['full_name']; 
													?>
														<label for="eventInput1">Production Date</label>
														<input class="form-control" type="text" name="prd_date" id="prd_date" value="<?php echo $cur_date ?>" readonly >
														<input type="hidden" id="branch_id" class="form-control"  name="branch_id" value="<?php echo $branch_id;?>">
														<input type="hidden" id="branch_name" class="form-control"  name="branch_name" value="<?php echo $branch_name;?>">
														<input type="hidden" id="full_name" class="form-control"  name="full_name" value="<?php echo $full_name;?>">
													</div>
												</div>
											</div>
											<div class="col-md-4">
												<div class="form-body">
													<div class="form-group">
														<label for="eventInput1">Chef</label>
														<select name="chef" id="chef" class="form-control select2" required>
															<option value="0">Select Chef</option>
															<?php  foreach($chef as $row)
																{
															?>
																<option value="<?php echo $row->chef_name ?>"><?php echo $row->chef_name ?></option>
															<?php
																} 
															?>
														</select>
													</div>
												</div>
											</div>
											<div class="col-md-4">
												<div class="form-body">
													<div class="form-group">
														<label for="eventInput1">Category</label>
														<select name="category" id="category" class="form-control chzn-select" required>
															<option value="">Select Category</option>
															<?php  foreach($category as $crow)
																{
															?>
																<option value="<?php echo $crow->pr_cat_id ?>"><?php echo $crow->pr_cat_name ?></option>
															<?php
																} 
															?>
														</select>
													

													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="card">				
								<div class="card-content collapse show">
									<div class="card-body">						
										<div class="row justify-content-md-right card_margin">
											<div class="text_increment">
												<div>
													<div class="row">							
														<div class="col-md-5">
															<div class="form-group">
																<select name="pname[]" id="pname" class="form-control chzn-select" required>
																	<option value="">Select Product</option>
																	<?php  foreach($recipe as $rcrow)
																		{
																	?>
																		<option value="<?php echo $rcrow->recipe_id ?>" data-chained="<?php echo $rcrow->pr_cat_id ?>" ><?php echo $rcrow->rname ?></option>
																	<?php
																		} 
																	?>
																</select>
																<input type="hidden" name="names[]" id="names" value="">
																<input type="hidden" name="rc_id[]" id="rc_id" value="">
																<input type="hidden" name="rc_no[]" id="rc_no" value="">
															</div>
														</div>
														<div class="col-md-2">
															<div class="form-group">
																<input class="form-control" type="text" name="uom[]" id="uom"  readonly  placeholder="UOM" />
															</div>
														</div>
														<div class="col-md-2">
															<div class="form-group">
																<input class="form-control" type="text" name="actual_yeild[]"  id="actual_yeild" placeholder="Yeild"/>
																<input class="form-control" type="hidden" name="yeild[]"  id="yeild" >
															</div>
														</div>									
													</div>
												</div>	
											</div>
										</div>
                    				</div>
								</div>
							</div>
							<div class="card" style="height: 81px;!important;">				
								<div class="card-content collapse show">
									<div class="card-body">
										<div class="">
											<div class="row card_margin">							
												<div class="col-md-2 mleft">
												</div>
												<div class="col-md-8 mleft">
													<button type="reset" class="btn btn-warning mr-1">
														<i class="ft-x"></i> Cancel
													</button>
													<button type="submit" class="btn btn-primary">
														<i class="la la-check-square-o"></i> Save
													</button>
												</div>
											</div>
										</div>	
									</div>
								</div>	
							</div>
								<div class="col-md-1 md-fab-wrapper plus mleft">
									<a href="javascript:void(0);" class="add_button" title="Add field"><i class="la la1 la-plus-circle"></i>
									<!--<img src="<?php //echo base_url(); ?>app-assets/images/add-icon.png" class="image_logo"/>-->
									</a>
								</div>
								<br/>
							
						</div>
					</div>
				</form>
			</section>
		</div>
	</div>
</div>
<?php //require('include/theme_customizer.php');?>
<?php 
 	$footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
?>
<script src="<?php echo base_url(); ?>assets/js/jquery-1.11.1.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/jquery.chained.js" type="text/javascript" ></script>
<script src="https://harvesthq.github.io/chosen/chosen.jquery.js"></script>
<script>
	$(document).ready(function() {
	    //alert("h");
		$("#pname").chained("#category");
        $('#pname,#category').chosen({width: '300px'});
	});

	$('#pname, #category').on('change', function(){
	    $('#pname, #category').trigger('chosen:updated');
	});
</script>
<script type="text/javascript">
	$(document).ready(function(){
		var maxField = 100; //Input fields increment limitation
		var addButton = $('.add_button'); //Add button selector
		var wrapper = $('.text_increment'); //Input field wrapper
		var x = 1; //Initial field counter is 1
		var counter = 1;
		//$(addButton).click(function(){ 
		$(document).on("click",".add_button",function() {  //Once add button is clicked
			if(x < maxField){ //Check maximum number of input fields
				x++; //Increment field counter
				$(wrapper).append('<div><div class="row"><div class="col-md-5"><div class="form-group"><select name="pname[]" id="pname'+counter+'" class="form-control select2" required><option value="">Select Product</option><?php  foreach($recipe as $rcrows) { ?><option value="<?php echo $rcrows->recipe_id ?>" data-chained="<?php echo $rcrows->pr_cat_id ?>" ><?php echo $rcrows->rname ?></option><?php } ?></select><input type="hidden" name="names[]" id="names'+counter+'" value=""><input type="hidden" name="rc_id[]" id="rc_id'+counter+'" value=""><input type="hidden" name="rc_no[]" id="rc_no'+counter+'" value=""></div></div><div class="col-md-2"><div class="form-group"><input class="form-control" type="text" name="uom[]" id="uom'+counter+'"  readonly  placeholder="UOM" /></div></div><div class="col-md-2"><div class="form-group"><input class="form-control" type="text" name="actual_yeild[]"  id="actual_yeild'+counter+'" placeholder="Yeild"/><input class="form-control" type="hidden" name="yeild[]"  id="yeild'+counter+'" ></div></div><div class="col-md-1 remove_button"><a href="javascript:void(0);" class="" title="Remove field"><img src="<?php echo base_url(); ?>app-assets/images/remove-icon.png" class="image_logo"/></a></div></div></div>'); 
				//alert(counter);
				$(function () {
					
					$('#pname' + counter).chained("#category");
					$('#pname'+ counter).chosen({width: '300px'});
						$('#category'+ counter).chosen({width: '300px'});
						//$(".select2").select2();
				});
				$('#pname'+ counter).on('change', function(){
				    $('#pname'+ counter).trigger('chosen:updated');
				});
				$('#category'+ counter).on('change', function(){
				    $('#category'+ counter).trigger('chosen:updated');
				});
				
				$('#pname' + counter).change(function(){
					var id = $(this).attr('id');
					// alert(id);
					id_length = id.length;
					if(id_length == 6) {
						counts = id.substr(-1);
						var i_name = $('#pname'+counts).val();
						var branch_id = $('#branch_id').val();
						$.ajax({
							type :'POST',
							dataType:'json',
							data : { iname : i_name,br_id : branch_id },
							url : '<?php echo base_url();?>index.php/Eshanya/get_RcpDetails',
							success: function(data) {
								//alert(data.rname);
								$('#names'+counts).val(data.rname);
								$('#rc_id'+counts).val(data.recipe_id);
								$('#uom'+counts).val(data.uom);
								$('#yeild'+counts).val(data.yeild);
								$('#rc_no'+counts).val(data.recipe_no);
							}
						});
						//$("#item_name"+ counts).attr('disabled', 'disabled');
					}
					else{
						counts = id.substr(-2);
						var i_name = $('#pname'+counts).val();
						var branch_id = $('#branch_id').val();
						//alert(i_name);
						//alert(brname);
						$.ajax({
							type :'POST',
							dataType:'json',
							data : { iname : i_name,br_id : branch_id },
							url : '<?php echo base_url();?>index.php/Eshanya/get_RcpDetails',
							success: function(data) {
								//alert(data.rname);
								$('#names'+counts).val(data.rname);
								$('#rc_id'+counts).val(data.recipe_id);
								$('#uom'+counts).val(data.uom);
								$('#yeild'+counts).val(data.yeild);
								$('#rc_no'+counts).val(data.recipe_no);
							}
						});
						//$("#item_name"+ counts).attr('disabled', 'disabled');
					}
				});
			}
			//alert(counter);
			counter++;
		});
		$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
			e.preventDefault();
			$(this).parent('div').remove(); //Remove field html
			x--; //Decrement field counter
			counter--;
		});
	});
</script>
<script>	
	$("#pname").change(function(){
		var i_name = $('#pname').val();
		var branch_id = $('#branch_id').val();
		//alert(i_name);
		//alert(branch_id);
		$.ajax({
			type :'POST',
			dataType:'json',
			data : { iname : i_name,br_id : branch_id },
			url : '<?php echo base_url();?>index.php/Eshanya/get_RcpDetails',
			success: function(data) {
				//alert(data.rname);
				$('#names').val(data.rname);
				$('#rc_id').val(data.recipe_id);
				$('#uom').val(data.uom);
				$('#yeild').val(data.yeild);
			    $('#rc_no').val(data.recipe_no);
			}
		});
		//$("#item_name").attr('disabled', 'disabled');
	});
</script>
</body>
</html>