<?php
	include('common/header.php');
?>
<div id="messages" style="color: green;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
	<style>
	.autocomplete {
	  position: relative;
	 
	}
	.autocomplete-items {
	 /* position: absolute;*/
	  border: 1px solid #d4d4d4;
	  border-bottom: none;
	  border-top: none;
	  z-index: 99;
	  top: 100%;
	  left: 0;
	  right: 0;
	}
	.autocomplete-items div {
	  padding: 10px;
	  cursor: pointer;
	  background-color: #fff; 
	  border-bottom: 1px solid #d4d4d4; 
	}
	.autocomplete-items div:hover {
	  background-color: #e9e9e9; 
	}
	.autocomplete-active {
	  background-color: DodgerBlue !important; 
	  color: #ffffff; 
	}

	</style>
	<div class="">
		<div class="col-xm-12">
			<div class="widget-box light-border">
				
				<div class="widget-body">
					<div class="widget-main">
						<div class="row">
							<div class="col-sm-12">
								 <?php $form_data=array('name'=>'dispense_manage','id'=>'dispense_manage','class'=>'form-horizontal','autocomplete'=>'off','onsubmit' => 'return validate_dispenser()','enctype'=>'multipart/form-data'); 
								echo form_open($form_action,$form_data); ?>	
                  				<section class="panel panel-default">
                 				 <header class="panel-heading bg-info lt font-bold"><?php echo $lable_customer_details?></header>
                  <!-- panel body start -->
                  <div class="panel-body bs-example form-horizontal">
                    <div class="">
					
                     <div class="hr hr12 dotted"></div>
                       <div class="">
                        <!-- main col-sm-12 -->
                      <div class="col-sm-12"> 
                         <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_branch_name?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <?php
									$company_array_data=$company_branch_array;
									$js1 = 'id="company_branch_id" class="form-control"';
									echo form_dropdown('company_branch_id', $company_array_data, $company_branch_id, $js1);
								?>
								<span class="red" id="branch_name_error"></span>			
                              </div>
														  
                            </div>
                          </div>

                           <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_customer_name?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
									<!--<input type="text" name="cutomer_name" value="" id="search" placeholder="Customer Name" class="form-control"  /> -->
									<!--<select tabindex="2" class="select2 select2-multiple form-control" name="customer_id" id="customer_list_id" multiple="multiple" data-placeholder="Choose">			
									 <option>white</option>
									  <option>purple</option>				
									</select>-->
									<!-- <?php
									$customer_array_data=$customer_array;
									$js1 = 'class="select2 select2-multiple form-control" name="customer_id" id="customer_id" multiple="multiple" data-placeholder="Choose"';
									echo form_dropdown('customer_id', $customer_array_data, $customer_id, $js1);
									?> -->
									<select class="select2 select2-multiple form-control" name="customer_id" multiple="multiple" id="customer_id" style="width: 250px;">
										<option value="default">Select Customer</option>
								    </select>
										
									<span class="red" id="customer_name_error"></span>
                              </div>	
                            </div>
                          </div>

                          <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_salse_person_name?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <!--<input type="text" name="sale_person_name" maxlength="150" value="" id="sale_person_name" placeholder="Sales Person Name" class="form-control"  /> -->
								<select class="js-example-basic-multiple" name="sale_person_name" id="sale_person_name" style="width: 250px;">
                                  <option value="">Select <?php echo $lable_salse_person_name?></option>
                                </select>
								<span class="red" id="sale_person_name_error"></span>
                              </div>
							
                            </div>
                          </div>

                          <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_Price;?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="c_price" onkeyup="Validate_number(this)" value="" maxlength="6" id="c_price" placeholder="Price" class="form-control"  />
								<span class="red" id="c_price1"></span>
                              </div>	
                            </div>
                    </div>
                        </div>
                            
                         <!-- </div> -->
                         <!-- main col-sm-12  close-->
                       </div> <!-- blank close -->
        </div><!-- blank close -->
      </div>   <!-- panel body close -->
    </section> <!-- section close -->

    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold"><?php echo $lable_dispenser_details?></header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">
            	<div class="col-sm-6">
                  <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required"><?php echo $lable_Product_Category; ?>:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                    <select name="dispenser_id" id="dispenser_id" onchange="get_dispenser(this.value);" class="form-control" >
                     <option value="0">Select Product Category</option>
               
                          <?php  
                              foreach ($product_category as  $pc) {?>
                                          
                               <option value="<?php echo $pc['product_category_id'];?>"><?php echo $pc['product_category_name'] ; ?><?php 
                                          
                                          }
      
                                        ?>
                                      
                    </select>  
                    <span id="country1" class="text-danger font-weight-bold"></span>
                   

                  </div>
                </div>

                </div> 

              <div class="col-sm-6">    
               <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_dispenser_name?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              	<select id="dispenser" name="dispenser_id">
                              	<option value="default">Select Dispenser Name</option>
                                 </select>
								<!--  <?php
									$refill_array_data=$refill_array;
									$js1 = 'id="dispenser_id"  class="form-control"';
									echo form_dropdown('dispenser_id', $refill_array_data, $dispenser_id, $js1);
								?> -->
								<span class="red" id="dispenser_name_error" ></span>
                         		</div>	
                </div>          
               </div>
            </div>
      
             <div class="col-sm-12">
                   <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_dispenser_quantity?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="dispenser_quantity" onkeyup="Validate_number(this)" value="" maxlength="6" id="dispenser_quantity" placeholder="<?php echo $lable_dispenser_quantity?>" class="form-control"  />
								<span class="red" id="dispenser_quantity_error"></span>
                              </div>	
                            </div>
                    </div>

                    <div class="col-sm-6">
                           <div class="form-group">
                               <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_instalaltion_date?> :<font style="color:red">*</font></label>
                                <div class="col-sm-7">  
                                  <div class="input-group">
                                   <input class="form-control date-picker" maxlength="12" id="sale_date" name="sale_date" type="text" data-date-format="dd-mm-yyyy">
                                    <span class="input-group-addon">
                                     <i class="fa fa-calendar bigger-110"></i>
                                    </span>
									
                                  </div>
								  <span class="red" id="sale_date_error"></span>
                                </div>
                            </div>
                    </div>
					   <div class="col-sm-6">
							   <div class="form-group">
								<label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_sales_type?>:<font style="color:red">*</font></label>
								  <div class="col-sm-7">
									<div class="radio">
										<label>
											<input type="radio" class="ace" name="sales_type" value="ftu"  id="ftu" >
											<span class="lbl"> FTU</span>
										</label>
										<label>
											
											<input type="radio" class="ace" name="sales_type" value="ort" id="otr">
											<span class="lbl"> ORT</span>
										</label>
										
									</div>
									<span class="red" id="sales_type_error"></span>
								  </div>	
								</div>
						</div>
				  
  
            </div>
      
        </div>
      </div>
    </section>


    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold"><?php echo $lable_contract_details?></header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">
                   <div class="col-sm-6">
                           <div class="form-group">
                            <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_is_contract_signed?> ?:	</label>
                              <div class="col-sm-7">
                                <div class="radio">
									<label>
										<input type="radio" value="1" class="ace" name="contract_sign"  id="contract_sign_yes" onchange="show();">
										<span class="lbl"> Yes</span>
									</label>
									<label>
										
										<input type="radio" value="0"  class="ace" name="contract_sign" id="contract_sign_no" onchange="hide();">
										<span class="lbl"> No</span>
									</label>
									
								</div>
								<span class="red" id="is_contract_sign_error"></span>
                              </div>	
                            </div>
                    </div>
              </div>
			<div class="col-sm-12" id="contract_div">
				<div class="col-sm-6" >
					   <div class="form-group">
						   <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_contract_start_date?> :<font style="color:red">*</font></label>
							<div class="col-sm-7">  
							  <div class="input-group">
							   <input class="form-control date-picker" name="contract_start_date" maxlength="12" id="contract_start_date" type="text" data-date-format="dd-mm-yyyy">
								<span class="input-group-addon">
								 <i class="fa fa-calendar bigger-110"></i>
								</span>
								
							  </div>
							  <span class="red" id="contract_start_date_error"></span>
							</div>
						</div>
				</div>

				 <div class="col-sm-6" >
					   <div class="form-group">
						   <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_contract_end_date?> :<font style="color:red">*</font></label>
							<div class="col-sm-7">  
							  <div class="input-group">
							   <input class="form-control date-picker" name="contract_end_date" maxlength="12" id="contract_end_date" type="text" data-date-format="dd-mm-yyyy">
								<span class="input-group-addon">
								 <i class="fa fa-calendar bigger-110"></i>
								</span>
							  </div>
							   <span class="red" id="contract_end_date_error"></span>
							</div>
						</div>
				</div>

				 <div class="col-sm-6" >
					   <div class="form-group">
						   <label for="client_code" class="col-sm-5 control-label required"><?php echo $lable_contract_attachment?> :<font style="color:red">*</font></label>
							<div class="col-sm-7">  
							  <div class="input-group">
							   <input type="file" id="attachment" name="attachment" size="33" onchange="previewImage(event)" multiple>
							   <span class="red" id="attachment_error"></span>
							  </div>
							</div>
						</div>
				</div>
			  
			   <div class="col-sm-6" >
				<div class="form-group" >  
						<label class="col-sm-5 control-label" for="form-field-2" ><?php echo $lable_comments;?><font style="color:red">*</font></label>
						<div class="col-sm-7" >	
							<?php	
								$admin_type_name_data=array('name'=>'comments',
														'id'=>'comments',
														'value'=> '',
														'cols'=>'53',
														'rows'=>'5'
														);
								echo form_textarea($admin_type_name_data,'');
								echo form_error('admin_type_name');
							?>
						</div>
				</div>
				</div>
			</div>
		</div>
	  </div>
	
	</section>
  </div>

</div>
</div>	
				</div>
			</div>
		</div>
		<div class="clearfix form-actions">
		<div class="col-md-offset-5 col-md-5">
			
			<button type="submit" name="btn_confirm" value="btn_confirm" class="btn btn-info left-icon mr-10">Next</button>
		</div>
	</div>	
    </form>
		<!-- /.col -->
	</div>
	
	<div class="space-4"></div>
		<!-- /.page-row -->
        <!-- /.page-content --> 
    </div>
    <!-- /.main-content --> 
	</div>
    <!-- /#ace-settings-container --> 
	</div>
	<!-- /.main-container-inner --> 

<?php
	include('common/footer.php');
?>
<script type="text/javascript">
function Validate_txt(txt) 
{
	 txt.value = txt.value.replace(/[^A-ZA-za-z0-9 \n\r\\]+/g, '');
	 txt.value= txt.value.replace(/\s+/g, " ");
}
function Validate_number(txt) 
{
	 txt.value = txt.value.replace(/[^0-9 \n\r]+/g, '');
	 txt.value= txt.value.replace(/\s+/g, " ");
}
	  $(document).ready(function(){
		  
		   $("#contract_div").hide();
		    $("#del").hide();
		  $(".js-example-tags").select2({
			  tags: true
			});
		  
		  	$(".select2").select2();  
			$(".select2").prop("multiple", "");
			
			/* var path='<?php echo base_url()?>index.php/<?php echo CUSTOMER_PATH;?>';
			auto_complete('<?php echo $company_id;?>',path,'company','company_list_id'); */
			$.ajax({
    			url:"<?php echo base_url();?>index.php/gc/dispenser_sale_data/customer",
   				method:"POST",
    			// data:{
     		// 	       company_branch_id:company_branch_id
    			// 	 },
    			success:function(data)
    					{
     					 $('#customer_id').html(data);
    					}
   			});



	  	  });
		  
		   $('#sale_date,#contract_start_date,#contract_end_date').datepicker({ dateFormat: 'dd-mm-yy' });       

function show(){
	$('#contract_div').show();
}
function hide(){
	$('#contract_div').hide();
}
                        
</script> 

<script>
 $('#company_branch_id').change(function(){
  var company_branch_id = $('#company_branch_id').val();
  if(company_branch_id != '')
  {
   $.ajax({
    url:"<?php echo base_url();?>index.php/gc/dispenser_sale_data/fetch_salse_person",
    method:"POST",
    data:{
      company_branch_id:company_branch_id
    },
    success:function(data)
    {
     $('#sale_person_name').html(data);
    }
   });
  }
  else
  {
   $('#sale_person_name').html('<option value="">Select Sales Person</option>');
  }
 });

 function get_dispenser()
{
  var dispenser_id = $('#dispenser_id').val();
  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/dispenser_sale_data/get_dispenser",
    method:"POST",
    data:{
      dispenser_id:dispenser_id
    },
    success:function(data)
    {
     $('#dispenser').html(data);
    }
   });
}

/* $.widget( "custom.catcomplete", $.ui.autocomplete, {
					_create: function() {
						this._super();
						this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
					},
					_renderMenu: function( ul, items ) {
						var that = this,
						currentCategory = "";
						$.each( items, function( index, item ) {
							var li;
							if ( item.category != currentCategory ) {
								ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
								currentCategory = item.category;
							}
							li = that._renderItemData( ul, item );
								if ( item.category ) {
								li.attr( "aria-label", item.category + " : " + item.label );
							}
						});
					}
				});
				
				 var data = [
					{ label: "anders" },
					{ label: "andreas"},
					{ label: "antal" },
					{ label: "annhhx10" },
					{ label: "annk K12" },
					{ label: "annttop C13" },
					{ label: "shreyas" },
					{ label: "anders andersson" },
					{ label: "andreas andersson" },
					{ label: "andreas johnson"}
				];
				$( "#search" ).catcomplete({
					delay: 0,
					source: data
				});	 */	

				
function validate_dispenser()
{
	var error=false;	
	var branch_name=$("#branch_name").val();	
	if(branch_name==0)
	{
		$("#branch_name_error").html("Please Select Branch Name");
		error=true;	
	}
	else
	{
		$('#branch_name_error').html("");
			
	}
	
	var customer_id=$("#customer_id").val();	
	if(customer_id=='default')
	{
		$("#customer_name_error").html("Please Select Customer");
		error=true;	
	}
	else
	{
		$('#customer_name_error').html("");
			
	}
	
	var sale_person_name=$("#sale_person_name").val();	
	if(sale_person_name=="")
	{
		$("#sale_person_name_error").html("Please Enter Sales Person Name");
		error=true;	
	}
	else
	{
		$('#sale_person_name_error').html("");
			
	}
	
	var c_price=$("#c_price").val();	
	if(c_price=="")
	{
		$("#c_price1").html("Please Enter Price");
		error=true;	
	}
	else
	{
		$('#c_price1').html("");
			
	}
	var dispenser_id=$("#dispenser_id").val();	
	if(dispenser_id=="")
	{
		$("#dispenser_name_error").html("Please Select Dispenser");
		error=true;	
	}
	else
	{
		$('#dispenser_name_error').html("");
			
	}
	
	var dispenser_quantity=$("#dispenser_quantity").val();	
	if(dispenser_quantity=="")
	{
		$("#dispenser_quantity_error").html("Please Enter Dispenser Quantity");
		error=true;	
	}
	else
	{
		$('#dispenser_quantity_error').html("");
			
	}
	
	var sale_date=$("#sale_date").val();	
	if(sale_date=="")
	{
		$("#sale_date_error").html("Please Enter Sales Date");
		error=true;	
	}
	else
	{
		$('#sale_date_error').html("");
			
	}
	
	
	var sales_type = $("input[name='sales_type']:checked").val();

	if(!sales_type)
	{
		$("#sales_type_error").html("Please select Salse Type FTU or OTR");
		error=true;			
	}
	else
	{
		$('#sales_type_error').html("");
			
	}
	
	
	var radioValue = $("input[name='contract_sign']:checked").val();

	if(!radioValue)
	{
		$("#is_contract_sign_error").html("Please select Is Contract Signed Yes or No");
		error=true;			
	}
	else
	{
		$('#is_contract_sign_error').html("");
			
	}
	
	//if($("#contract_start_date"))
	if ($("#contract_div").css('display') == 'block' )
	{
		
		var contract_start_date=$("#contract_start_date").val();	
		if(contract_start_date=="")
		{
			$("#contract_start_date_error").html("Please Select Contract Start Date");
			error=true;	
		}
		else
		{
			$('#contract_start_date_error').html("");
				
		}
		
		var contract_end_date=$("#contract_end_date").val();	
		if(contract_end_date=="")
		{
			$("#contract_end_date_error").html("Please Select Contract End Date");
			error=true;	
		}
		else
		{
			$('#contract_end_date_error').html("");
				
		}
	}
	
	
	
	if(error==true)
	{
		return false;
	}
	else
	{
		return true;
	}
	
}
</script>