<?php require('include/header.php');?>

   <?php require('include/sidenav.php');?>

   
    <!-- 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">DC Price</h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="index-2.html">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">DC Price</a>
                  </li>
                  <li class="breadcrumb-item active">DC Price
                  </li>
                </ol>
              </div>
            </div>
          </div>
          
        </div>
        <div class="content-body"><!-- Basic form layout section start -->
<section id="basic-form-layouts">
	<form class="form" action="<?php echo site_url('User/updateDcPriceC'); ?>" method="POST" autocomplete="off">
	<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">DC Price</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">
							<div class="row justify-content-md-center">
								<div class="col-md-4">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">User</label>
											<select name="branch_id" id="branch_id" class="select2 form-control" required >
												<option value="">Select Username</option>
												<?php  foreach($username as $row)
													{
														echo '<option value="'.$row->branch_id.'">'.$row->username.'</option>';
													} 
												?>
											</select>
										</div>
									</div>
								</div>
							<!--	<div class="col-md-4">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Category</label>
											<select name="cat_id" id="cat_id" class="select2 form-control" >
												<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 class="col-md-4">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Product</label>
											<select name="pname[]" id="pname" class="form-control select2" >
												<option value="0">Select Product</option>
												<?php /* foreach($recipe as $rcrow)
													{
												?>
													<option value="<?php echo $rcrow->recipe_no ?>" class="<?php echo $rcrow->pr_cat_id ?>" ><?php echo $rcrow->rname ?></option>
												<?php
													} */
												?>
											</select>
										</div>
									</div>
								</div>-->
							</div>
						<!--	<div class="row justify-content-md-center">
							    <div class="col-md-3">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Base Price</label>
											<input type="text" class="form-control" id="base_price" name="base_price" value="" required placeholder="Base Price">
										</div>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">GST Rate(%)</label>
											<select name="gst_rate" id="gst_rate" class="form-control select2" required>
												<option value="">Select Tax</option>
												<?php /*  foreach($tax as $row)
													{
														echo '<option value="'.$row->tax_percentage.'">'.$row->tax_percentage.'</option>';
													} */
												?>
											</select>
										</div>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Tax Amt</label>
											<input type="text" class="form-control" id="gst" name="gst" value="" required placeholder="GST">
										</div>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-body">
										<div class="form-group">
											<label for="eventInput1">Price</label>
											<input type="text" class="form-control" id="tprice" name="tprice" value="" required placeholder="Price">
										</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">
						<div class="text_increment">
							<div>
								<div class="row">
									<div class="col-md-3">
										<div class="form-group">
											<select name="pname[]" id="pname" class="form-control select2" >
												<option value="0">Select Product</option>
												<?php  foreach($recipe as $rcrow)
													{
												?>
													<option value="<?php echo $rcrow->recipe_no ?>" class="<?php echo $rcrow->pr_cat_id ?>" ><?php echo $rcrow->rname ?></option>
												<?php
													} 
												?>
											</select>
										</div>
									</div>
									<div class="col-md-2">
										<div class="form-group">
											<input type="text" class="form-control" id="base_price" name="base_price[]" value="" required placeholder="Base Price">
										</div>
									</div>
									<div class="col-md-2">
										<div class="form-group">
											<select name="gst_rate[]" id="gst_rate" class="form-control select2" required>
												<option value="">Select Tax</option>
												<?php  foreach($tax as $row)
													{
														echo '<option value="'.$row->tax_percentage.'">'.$row->tax_percentage.'</option>';
													} 
												?>
											</select>
										</div>
									</div>
									<div class="col-md-2">
										<div class="form-group">
											<input type="text" class="form-control" id="gst" name="gst[]" value="" required placeholder="GST">
										</div>
									</div>
									<div class="col-md-2">
										<div class="form-group">
											<input type="text" class="form-control" id="tprice" name="tprice[]" value="" required placeholder="Price">
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
                </div>
			</div>
		</div>
		
		<div class="card">
				<div class="card-content collapse show">
					<div class="card-body">
						<div class="text-right">
							<div class="row">
							    <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 class="col-md-1 md-fab-wrapper plus">
					<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>
	    </div>
    </form>
</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
    <!-- END: Content-->


   <?php //require('include/theme_customizer.php');?>

   <?php require('include/footer.php');?>
   
   
   <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-3"><div class="form-group"><select name="pname[]" id="pname'+counter+'" class="form-control select2" ><option value="0">Select Product</option><?php  foreach($recipe as $rcrow) { ?><option value="<?php echo $rcrow->recipe_no ?>" class="<?php echo $rcrow->pr_cat_id ?>" ><?php echo $rcrow->rname ?></option><?php } ?></select></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" id="base_price'+counter+'" name="base_price[]" value="" required placeholder="Base Price"></div></div><div class="col-md-2"><div class="form-group"><select name="gst_rate[]" id="gst_rate'+counter+'" class="form-control select2" required><option value="">Select Tax</option><?php  foreach($tax as $row) { echo '<option value="'.$row->tax_percentage.'">'.$row->tax_percentage.'</option>'; } ?></select></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" id="gst'+counter+'" name="gst[]" value="" required placeholder="GST"></div></div><div class="col-md-2"><div class="form-group"><input type="text" class="form-control" id="tprice'+counter+'" name="tprice[]" value="" required placeholder="Price"></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 () {
						$(".select2").select2();
						$('#quantity' + counter).keypress(function(e) {
							var a = [];
							var k = e.which;
							for (i = 46; i < 58; i++)
							a.push(i);
							if (!($.inArray(k,a)>=0))
							e.preventDefault();
						});
					});
					
					$('#gst_rate' + counter).change(function(){
						var id = $(this).attr('id');
						// alert(id);
						id_length = id.length;
						if(id_length == 9) {
							counts = id.substr(-1);
							var tax = $('#gst_rate'+counts).val();
			                var basic = $('#base_price'+counts).val();
			                var tax_amt = ((parseFloat(basic) * parseFloat(tax))/100).toFixed(2);
			                var price = Math.round(parseFloat(basic) + parseFloat(tax_amt));
			                
			                $('#gst'+counts).val(tax_amt);
			                $('#tprice'+counts).val(price);
			            }
						else{
						    counts = id.substr(-2);
							var tax = $('#gst_rate'+counts).val();
			                var basic = $('#base_price'+counts).val();
			                var tax_amt = ((parseFloat(basic) * parseFloat(tax))/100).toFixed(2);
			                var price = Math.round(parseFloat(basic) + parseFloat(tax_amt));
			                
			                $('#gst'+counts).val(tax_amt);
			                $('#tprice'+counts).val(price);
						}
					});
					
					$('#base_price' + counter).change(function(){
						var id = $(this).attr('id');
						// alert(id);
						id_length = id.length;
						if(id_length == 11) {
							counts = id.substr(-1);
							var basic = $('#base_price'+counts).val();
			                var tax = $('#gst_rate'+counts).val();
							
			                if(!($.isNumeric(tax)))
                			{
                				tax = 0;
                			}
                			var tax_amt = ((parseFloat(basic) * parseFloat(tax))/100).toFixed(2);
                			var price = Math.round(parseFloat(basic) + parseFloat(tax_amt));
			                $('#gst'+counts).val(tax_amt);
			                $('#tprice'+counts).val(price);
			            }
						else{
						    counts = id.substr(-2);
							var basic = $('#base_price'+counts).val();
			                var tax = $('#gst_rate'+counts).val();
							
			                if(!($.isNumeric(tax)))
                			{
                				tax = 0;
                			}
                			var tax_amt = ((parseFloat(basic) * parseFloat(tax))/100).toFixed(2);
                			var price = Math.round(parseFloat(basic) + parseFloat(tax_amt));
			                $('#gst'+counts).val(tax_amt);
			                $('#tprice'+counts).val(price);
						}
					});
				}
				//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>
		$(document).ready(function() {
			$("#pname").chained("#cat_id");
		});
		
		$('#branch_id').change(function() {
		    var pname = $('#branch_id').val();
		    //alert(pname);
		});
	</script>
	<script>
		$('#gst_rate').change(function() {
			var tax = $('#gst_rate').val();
			var basic = $('#base_price').val();
			var tax_amt = ((parseFloat(basic) * parseFloat(tax))/100).toFixed(2);
			var price = Math.round(parseFloat(basic) + parseFloat(tax_amt));
			$('#gst').val(tax_amt);
			$('#tprice').val(price);
		});
		
		$('#base_price').keyup(function() {
			var basic = $('#base_price').val();
			var tax = $('#gst_rate').val();
			if(!($.isNumeric(tax)))
			{
				tax = 0;
			}
			var tax_amt = ((parseFloat(basic) * parseFloat(tax))/100).toFixed(2);
			var price = Math.round(parseFloat(basic) + parseFloat(tax_amt));
			$('#gst').val(tax_amt);
			$('#tprice').val(price);
		});
	</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>