<?
   
	$fld[1]='jcno';
	$fld[2]='regno';
	$fld[3]='vehiclename';
	$fld[4]='model';
	$fld[5]='customer';
	$fld[6]='instype';
	$fld[7]='insurance';
	$fld[8]='jobtype';
	$fld[9]='receivedby';
	$fld[10]='work_status';
	$fld['11']='fin_date';
	$fld['12']='inv_date';


	$i=1;


 	$sql1="select * from gateentry where  ";

	foreach($fld as $field)
 	{

              $j=1;         

		$var[$i]=$field.'1';


              $fld_list[$i]=mysqli_query($db,"select distinct($field) from gateentry where  brcode='$brcode' and entrydate between '$fromdt' and '$todt' order by $field ");

               if(($$var[$i])&&($$var[$i]!='All')){


                      if($field=='jcno')
			 	$jcno[]=$$var[$i];

			 if($field=='regno')
			 	$regno[]=$$var[$i];

                      if($field=='vehiclename')
			 	$vehiclename[]=$$var[$i];

			 if($field=='model')
			 	$model[]=$$var[$i];

                      if($field=='customer')
			 	$customer[]=$$var[$i];

			 if($field=='instype')
			 	$instype[]=$$var[$i];

                      if($field=='insurance')
			 	$insurance[]=$$var[$i];

			 if($field=='jobtype')
			 	$jobtype[]=$$var[$i];

                      if($field=='receivedby')
			 	$receivedby[]=$$var[$i];

			 if($field=='work_status')
			 	$work_status[]=$$var[$i];
     
                      if($field=='fin_date')
			 	$fin_date[]=$$var[$i];

			 if($field=='inv_date')
			 	$inv_date[]=$$var[$i];

                       }
                     else
                         {
                          unset($$field);
			      $$field= array();
                         }
                       $$field=array_unique($$field);
                         


                       foreach($$field as $fld_val)
 		           {         
              
                           if(($fld_val)&&($fld_val!='All')){

            			$val[$i]  =substr($fld_val,1);  

	     			$indic[$i]=substr($fld_val,0,1);
  
            			if($indic[$i]=='*'){

                           		if($j==1)
                 	               	$sql1.='( ';

               			if($j>1)
                			 	$sql1.=' or ';

        	 			$sql1.=$field . "<>'".$val[$i]."'";

              			$j++;

                                  $not_val[$i]=$val[$i];
                                   
            			}

            	      		else
            			{

                           		if($j==1)
                 			 	$sql1.='( ';
               			if($j>1)
                 			 	$sql1.=' or ';

               			$sql1.=$field . "='".$fld_val."'";
            
              			$j++;
            	     	      }
 	 	          }         //close if condition

 		 }//for each
           
            

               if(($$field)&&($$field!='All')){

                   if($j>1)
   		          $sql1.=') and ';
                   }
		$i++;

         	

 	   }              //close forloop




 	$sql1.=  " entrydate between '$fromdt' and '$todt' and brcode='$brcode' order by jcno desc";

 	$sql=mysqli_query($db,$sql1);

//echo $sql1;


  ?>
