<?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">BOM</h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="#">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">BOM</a>
                  </li>
                  <li class="breadcrumb-item active">BOM
                  </li>
                </ol>
              </div>
            </div>
          </div>
          
        </div>
        <div class="content-body"><!-- Basic form layout section start -->
<section id="basic-form-layouts">
	



	<div class="row justify-content-md-center">
		<div class="col-md-12">
			<div class="card">
				<!--<div class="card-header">
					<h4 class="card-title" id="basic-layout-form-center">Production</h4>
					<a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
					<div class="heading-elements">
						<ul class="list-inline mb-0">
							<li><a data-action="collapse"><i class="ft-minus"></i></a></li>
							<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
							<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
							<li><a data-action="close"><i class="ft-x"></i></a></li>
						</ul>
					</div>
				</div>-->
				<div class="card-content collapse show">
					<div class="card-body">
						<form class="form" autocomplete="off" action="<?php echo site_url('Production/addBOM');?>" method="post">
							<div class="row justify-content-md-center">
								<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">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</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 id="category" name="category" class="select2"  >
                                            <option value="">Select</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 class="row">
								<div class="col-md-3 mleft">
								    <div class="form-body">
    									<div class="form-group">
    									    <label for="eventInput1">Product</label>
    									<!--	<select name="pname" id="pname" class="form-control chzn-select" required>
    											<option value="0">Select</option>
    											<?php /* foreach($recipe as $rcrow)
    												{
    											?>
    											    <option value="<?php echo $rcrow->recipe_id ?>" class="<?php echo $rcrow->pr_cat_id ?>" ><?php echo $rcrow->rname ?></option>
    											<?php
    												} */
    											?>
    										</select>-->
    											<select name="pname" id="pname" class="form-control"  >
                                              <option value="">Select</option>
                                            </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>
								<div class="col-md-2">
								    <div class="form-body">
    									<div class="form-group">
    									    <label for="eventInput1">UOM</label>
    									    <input class="form-control" type="text" name="uom" id="uom"  readonly  placeholder="UOM" />
    									</div>
    								</div>
								</div>
								<div class="col-md-3">
								    <div class="form-body">
    									<div class="form-group">
    									    <label for="eventInput1">Select</label>
    										<select name="ptype" id="ptype" class='form-control select2' required='required'>
										<option value="">Select</option>
    										<option value="yeild">Yeild</option>
    										<option value="batch">Batch</option>
    									</select>
    									</div>
    								</div>
								</div>
								<div class="col-md-2 yld" style="display:none;">
								    <div class="form-body">
        								<div class="form-group">
        								    <label for="eventInput1">Yeild</label>
        									<input class="form-control" type="text" name="actual_yeild"  id="actual_yeild" />
        										<input class="form-control" type="hidden" name="yeild"  id="yeild" >
        										<input class="form-control" type="hidden" name="batch"  id="batch" >
        								</div>
        							</div>
								</div>
								<div class="col-md-2 btch" style="display:none;">
								    <div class="form-body">
        								<div class="form-group">
        								    <label for="eventInput1">Batch</label>
        									<input class="form-control" type="text" name="actual_batch"  id="actual_batch" />
        							    </div>
        							</div>
								</div>
							</div>
							<div class="result"></div>
						    </br>
							<div class="form-actions text-center">
								<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>
						</form>	
                        </br>
						    
					</div>
				</div>
				<br/>
			</div>
		</div>
	</div>

</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
    <?php //require('include/theme_customizer.php');?>

   <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>

	<script>
	/*	$(document).ready(function() {
			$("#pname").chained("#category");
		}); */
		
	//	$(document).ready(function() {  
            $("#category").change(function(){  
              /*dropdown post *///
              var cat_id = $("#category").val();
              //alert(cat_id);
              $.ajax({  
                    url:"<?php echo base_url();?>index.php/Production/buildDropProduct",  
                    data: {id : cat_id},  
                    type: "POST",  
                    success:function(data){ 
                        //alert(data)
                        $("#pname").html(data);  
                    }  
                });  
            });
      //  });
	</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 },
				url : '<?php echo base_url();?>index.php/Production/get_RcpDetails',
				success: function(data) {
				//	alert(data.yeild);
					$('#names').val(data.rname);
					$('#rc_id').val(data.recipe_id);
					$('#uom').val(data.uom);
					$('#yeild').val(data.yeild);
					$('#batch').val(1);
				    $('#rc_no').val(data.recipe_no);
				}
			});
			//$("#item_name").attr('disabled', 'disabled');
		});
		
		$("#ptype").change(function(){
		    var ptype=$('#ptype').val();
			//alert(yel);
			if(ptype == 'yeild'){
			    $(".yld").show();
				$(".btch").show();
				$("#actual_yeild").attr('readonly', false);
				$("#actual_batch").attr('readonly', true);
				$("#actual_yeild").val('');
				$("#actual_batch").val('');
			}
		    else if(ptype == 'batch'){
		         $(".yld").show();
				$(".btch").show();
				$("#actual_yeild").attr('readonly', true);
				$("#actual_batch").attr('readonly', false);
				$("#actual_yeild").val('');
				$("#actual_batch").val('');
		    }
		});
		
		$("#actual_yeild").keyup(function(){
		    var act_yeild = $('#actual_yeild').val();
			var pname = $('#pname').val();
			var yeild = $('#yeild').val();
			var batch = $('#batch').val();
			var rc_no = $('#rc_no').val();
			
			var out = ((parseFloat(act_yeild) * parseFloat(batch))/yeild).toFixed(2);
			//alert(rc_no);
			$('#actual_batch').val(out);
			$.ajax({  
            url:"<?php echo base_url();?>index.php/Production/fetchbom",  
                    data: { act_yld: out,name: pname,yld: yeild,rc_no:rc_no},  
                    type: "POST",  
                    success:function(data){  
                      $(".result").html(data);
					$('#yeild').val(ya);
					// $('#yeild1').css("display","none");
					$('#yeild').css("display","block");
					//$('#yeild').blur();
            }  
          });
			
		/*	$.post( "<?php echo base_url();?>index.php/Production/fetchbom.php", { act_yld: out,name: pname,yld: yeild })
				.success(function(data) {
					
					$(".result").html(data);
					$('#yeild').val(ya);
					// $('#yeild1').css("display","none");
					$('#yeild').css("display","block");
					//$('#yeild').blur();
				});*/
				if ($('#result').html() == '')
				{
					$('#ris_count').val(0);
				}
				else{
					$('#ris_count').val(1);
				}
				var riname = $('input[name="name[]"]').map(function(){ return this.value }).get();
				var rsname = $('input[name="sub_name[]"]').map(function(){ return this.value }).get();
				var ricount = riname.length;
				var rscount = rsname.length;
				var ris_count = ricount + rscount;
				//$('#ris_count').val(ris_count);
		});
		
		$("#actual_batch").keyup(function(){
		    var act_batch = $('#actual_batch').val();
			var pname = $('#pname').val();
			//alert(pname);
			var yeild = $('#yeild').val();
			var batch = $('#batch').val();
			var rc_no = $('#rc_no').val();
			var out = ((parseFloat(act_batch) * parseFloat(yeild))/batch).toFixed(2);
			//alert(out);
			$('#actual_yeild').val(out);
			$.ajax({  
            url:"<?php echo base_url();?>index.php/Production/fetchbom",  
                    data: { act_yld: out,name: pname,yld: yeild,rc_no:rc_no},  
                    type: "POST",  
                    success:function(data){  
                      $(".result").html(data);
					$('#yeild').val(ya);
					// $('#yeild1').css("display","none");
					$('#yeild').css("display","block");
					//$('#yeild').blur();
            }  
          });
			
		/*	$.post( "<?php echo base_url();?>index.php/Production/fetchbom.php", { act_yld: out,name: pname,yld: yeild })
				.success(function(data) {
					
					$(".result").html(data);
					$('#yeild').val(ya);
					// $('#yeild1').css("display","none");
					$('#yeild').css("display","block");
					//$('#yeild').blur();
				});*/
				if ($('#result').html() == '')
				{
					$('#ris_count').val(0);
				}
				else{
					$('#ris_count').val(1);
				}
				var riname = $('input[name="name[]"]').map(function(){ return this.value }).get();
				var rsname = $('input[name="sub_name[]"]').map(function(){ return this.value }).get();
				var ricount = riname.length;
				var rscount = rsname.length;
				var ris_count = ricount + rscount;
				//$('#ris_count').val(ris_count);
		});
	</script>
	
  </body>
  <!-- END: Body-->

<!-- Mirrored from pixinvent.com/modern-admin-clean-bootstrap-4-dashboard-html-template/html/ltr/vertical-modern-menu-template/form-layout-basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Apr 2020 09:38:02 GMT -->
</html>