<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 }  ?>
					   <form action="<?php echo site_url();?>admin/Quotation/save_quotation" method="post">
							<div class="row">
							<div class="form-group">
								<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>
								
								<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>

							</div>
						</div>
							<br />
							<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 name="product" class="form-control" required>
									<option value="">--SELECT--</option>
									<?php
									foreach($product_info as $p)
									{
										?>
										<option value="<?=$p['id']?>"><?=$p['product']?></option>
										<?php										
									}
									?>
									</select>
								</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 /><br /><br />
					
           <div style="overflow-x:auto;">
              
     <table id="example" class="table table-striped table-bordered responsive">
        <thead>
            <tr>
				<th>Sort Order</th>
				<th>Category</th>
				<th>Component</th>				
				<th>Price</th>                
				<th>Quantity</th>                
				<th>Amount</th>                
            </tr>
        </thead>
        <tbody>
			  
<?php 
$sql = "SELECT * FROM category where IsActive=0";
        $record = $this->db->query($sql);
        $cat_info=$record->result_array();
		$i=1;
foreach($cat_info as $r)
{
	$category_id=$r['id'];
	 $sql1 = "SELECT * FROM component where IsActive=0 and category='$category_id'";
        $record1 = $this->db->query($sql1);
        $com=$record1->result_array();
		
?>							
					<tr class="gradeX">
					<td><input type="text" value="" id="sort_order" name="sort_order[]" class="ui-dform-text form-control"></td>
					<td><input type="text" value="<?php echo $r['category']?>" id="category_name" name="category[]" 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" name="valor" class="valor" value="<?=$r['id']?>">
					<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 col-md-offset-7">
								Tamount:
							 </div>
							 <div class="col-md-4">

							 <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-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();
								//	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,
												  //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]);
									}		      	
									});
								});
								
								
		 $(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>
	</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>
      