<link rel="stylesheet" href="<?php echo site_url();?>assets/beatpicker/css/BeatPicker.min.css"/>
<link rel="stylesheet" href="<?php echo site_url();?>assets/beatpicker/css/demos.css"/>
<link rel="stylesheet" href="<?php echo site_url();?>assets/beatpicker/css/prism.css"/>
<script src="<?php echo site_url();?>assets/beatpicker/js/BeatPicker.min.js"></script>
<script src="<?php echo site_url();?>assets/beatpicker/js/prism.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<?php date_default_timezone_set('Asia/Kolkata');?>
<div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header">Quotation</h3>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                       <!--    <a href="<?php echo site_url();?>admin/Company/user_add" class="btn btn-info"> Add User</a>-->
                    <div class="panel panel-default">
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <?php $success_message = $this->session->flashdata('success_message');
                            if (!empty($success_message)) {?>
                                <div class="alert alert-success">
                                      <a class="close" data-dismiss="alert" href="components-popups.html#" aria-hidden="true">×</a>
                                      <strong><?php echo $this->session->flashdata('success_message');  ?></strong>
                                </div> 
                            <?php }  ?>
                            <?php $failure_message = $this->session->flashdata('failure_message');
                            if (!empty($failure_message)) {?>
                                <div class="alert alert-warning">
                                      <a class="close" data-dismiss="alert" href="components-popups.html#" aria-hidden="true">×</a>
                                      <strong><?php echo $this->session->flashdata('failure_message');  ?></strong>
                                </div> 
                            <?php }  ?>
							    <script type="text/javascript">
function personalia_showform(obj){
	var no_of_vehicle = obj.value;
	var pers_gesl = obj.value;
<?php echo "window.location.href='add_quotation?cat=' +pers_gesl";?>
}
</script>
<?php
if($_GET['cat'])
{
	$cat=$_GET['cat'];
}
?>
					   <form action="<?php echo site_url();?>admin/Quotation/save_quotation" method="post" enctype="multipart/form-data">
							<div class="row">
							<div class="form-group">
								<label class="control-label col-md-2">Product :<font color="red">*</font></label>
								<div class="col-md-4">
						<select onchange="personalia_showform(this);"  name="product" class="form-control" required>
									<?php
									if($_GET['cat'])
									{
										$cat=$_GET['cat'];
										$sql = "SELECT * FROM product where IsActive=0 and id='$cat'";
										$record = $this->db->query($sql);
										$product=$record->row('product');
										$pid=$record->row('id');
										?>
										<option value="<?=$pid?>"><?=$product?></option>
										<?php
									}
									else
									{
									?>
									<option value="">--SELECT--</option>
									<?php
									}
									foreach($product_info as $p)
									{
										?>
										<option value="<?=$p['id']?>"><?=$p['product']?></option>
										<?php										
									}
									?>
									</select>
								</div>
								
								<?php
								if($_GET['cat'])
								{
									$cat=$_GET['cat'];
								?>
								<label class="control-label col-md-2">Tender No:<font color="red">*</font></label>
								<div class="col-md-4">
								<input type="text" required name="tender_no" value="<?php echo set_value('tender_no')?set_value('tender_no'):'';?>" class="ui-dform-text form-control">
								</div>
								
						

							</div>
						</div>
							<br />
							<div class="row">
							<div class="form-group">
		<label class="control-label col-md-2">Tender Date:<font color="red">*</font></label>
								<div class="col-md-4">

					   <div class="input-group date" id='datetimepicker2'>
						<input class="form-control" required type="text" placeholder="To" value="<?php echo set_value('tender_date')?set_value('tender_date'):date('dd-mm-Y');?>" name="tender_date">
						  <span class="input-group-addon">
							<span class="glyphicon glyphicon-calendar"></span>
						   </span>
						</div>
						</div>
								
								<label class="control-label col-md-2">Tender Due Date:<font color="red">*</font></label>
								<div class="col-md-4">

					   <div class="input-group date" id='datetimepicker_to'>
						<input class="form-control" required type="text" placeholder="To" value="<?php echo set_value('tender_due_date')?set_value('tender_due_date'):''?>" name="tender_due_date">
						  <span class="input-group-addon">
							<span class="glyphicon glyphicon-calendar"></span>
						   </span>
						</div>
						</div>

							</div>
						</div>
						<br />
							<div class="row">
							<div class="form-group">
								<label class="control-label col-md-2">No.of Pieces:<font color="red">*</font></label>
								<div class="col-md-4">
								<input type="text" required name="pieces" value="<?php echo set_value('pieces')?set_value('pieces'):'';?>" class="ui-dform-text form-control">
								</div>
								
								<label class="control-label col-md-2">Location:<font color="red">*</font></label>
								<div class="col-md-4">
								<input type="text" required name="location" value="<?php echo set_value('location')?set_value('location'):'';?>" class="ui-dform-text form-control">
								</div>

							</div>
						</div>
							<br /><br />
					
           <div style="overflow-x:auto;">
              
     <table id="example" class="table table-striped table-bordered responsive">
        <thead>
            <tr>
				<th>Category</th>
				<th>Component</th>				
				<th>Price</th>                
				<th>Quantity</th>                
				<th>Amount</th>                
            </tr>
        </thead>
        <tbody>
			  
<?php 
$sql = "SELECT * FROM component where IsActive=0 and master_product='$cat' group by category";
//echo $sql;
        $record = $this->db->query($sql);
        $cat_info=$record->result_array();
		$i=1;
foreach($cat_info as $r)
{
	$category_id=$r['category'];
	 $sql1 = "SELECT * FROM category where category_no='$category_id'";
        $record1 = $this->db->query($sql1);
        $com=$record1->result_array();
		
?>							
					<tr class="gradeX">
				<input type="hidden" value="" id="sort_order" name="sort_order[]" >
					<td><input type="text" value="<?php echo $com[0]['category']?>" id="category_name" name="category[]" readonly class="ui-dform-text form-control"></td>
					<td>
					<input type="text" tabindex=<?=$i?> required value="<?php echo set_value('component')?set_value('component'):'';?>" name="component[]" id="component_<?=$i?>" data-type="component" class="ui-dform-text form-control autocomplete_txt3" autocomplete="off">
					</td>
					<td><input type="text" value="" id="price_<?=$i?>" name="price[]" class="ui-dform-text form-control quantity"></td>
					<input type="hidden" value="" id="component_no_<?=$i?>" name="component_no[]" class="form-control">
					<input type="hidden" name="valor[]" class="valor" value="<?=$com[0]['category_no']?>">
					<input type="hidden" name="sorder[]" value="<?=$com[0]['sorder']?>">
					<td><input type="text" name="quantity[]" value="1" id="quantity_<?=$i?>" class="quantity ui-dform-text"></td>
					<td><input type="text" name="amount[]" value="" id="totamtgst_<?=$i?>" class="tamount ui-dform-text"></td>

							 </tr> 		
<?php
$i++;
}

?>	
                      
  </tbody>
    </table>
					
							<div class="col-md-1 ">
								Tamount:
							 </div>
							 <div class="col-md-3">

							 <input type="number" required step="0.0001" readonly class="ui-dform-text form-control" tabindex=<?=$i?> value="<?php echo set_value('tamount')?set_value('tamount'):'';?>" id="tamount" name="tamount" placeholder="Total Amount" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;">
							</div>
							
								<div class="col-md-1">
								Status:
							 </div>
							 <div class="col-md-3">
								<select name="cstatus" class="form-control">
								<option value="Complete">Complete</option>								
								<option value="Incomplete">Incomplete</option>								
								</select>
							</div>
							<div class="col-md-1">
								Doccument:
							 </div>
							<div class="col-md-3">
						<input type="file" required name="je" class="form-control">
							</div>
							<br /><br /><br />
							<div class="col-md-2 col-md-offset-6">
								<div class="col-md-1">
								<input href type="submit" name="submit" value="SUBMIT >>" target="_blank" class="btn btn-warning pull-right" >	
								</div>
							</div>
						</form>
		
					<script>
					$(document).on('focus','.autocomplete_txt3',function(){
									type = $(this).data('type');
									if(type =='component' )autoTypeNo=0; 
									 var valor = $(this).parents('tr').find('.valor').val();
									 var product = '<?php echo $cat ;?>';
								//	alert(id);
									$(this).autocomplete({
										source: function( request, response ) {
								//	alert(valor);
											//alert(category);
											//alert($("#category_id").val());
											$.ajax({
												url : 'http://pctest.spectracloud.net/spectra/admin/Quotation/auo_product3',
												dataType: "json",
												method: 'post',
												
												data: {
												 category: valor,
												 product: product,
												  //alert(category);												  
												   name_startsWith: request.term,
												   type: type 
												},
												 success: function( data ) {
													 response( $.map( data, function( item ) {
														var code = item.split("|");
														return {
															label: code[autoTypeNo],
															value: code[autoTypeNo],
															data : item
														}
													}));
												}
											});
										},
										autoFocus: true,	      	
										minLength: 0,
										select: function( event, ui ) {
											var names = ui.item.data.split("|");
											id_arr = $(this).attr('id');
											id = id_arr.split("_");
											//alert(names);
											$('#component_'+id[1]).val(names[0]);
											$('#price_'+id[1]).val(names[1]);
											$('#component_no_'+id[1]).val(names[2]);
											$('#totamtgst_'+id[1]).val(names[1]);

											
									}		      	
									});
								});
								
								
		 $(document).on('change keyup blur','.quantity',function(){
			id_arr = $(this).attr('id');
			id = id_arr.split("_");
			quantity = $('#price_'+id[1]).val();
			price = $('#quantity_'+id[1]).val();
			if( quantity!='' && price !='' ) $('#totamtgst_'+id[1]).val( (parseFloat(price)*parseFloat(quantity)).toFixed());	
			
			 calculateTotal4();
		});
		function calculateTotal4(){
									tamount = 0 ; total1 = 0; 
									$('.tamount').each(function(){
										if($(this).val() != '' )tamount += parseFloat( $(this).val() );
									});
									$('#tamount').val(tamount.toFixed() );

										total1 = tamount;
										
										
										
								}
			  
	</script>
	<?php
			}
			?>
	</div>					   
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->            
        </div>
        <!-- /#page-wrapper -->


<script>
function doconfirm()
{
    job=confirm("Are you sure to delete permanently?");
    if(job!=true)
    {
        return false;
    }
}
</script>
		
             <script>

$(document).keypress(function(e) {
    if(e.which == 13) {
e.preventDefault();
            // Do something here if the popup is open
            //alert("dd")
            var index = $('.ui-dform-text').index(document.activeElement) + 1;
            $('.ui-dform-text').eq(index).focus();
        
    }
}); 
</script>
	
      