<?php include 'header1f.php';?>
<?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	$customer_name = "";
	$bphone = "";
	$bcity = "";
	$bstate = "";
	$ageto = "";
	$industry = "";
	$description = "";
	$lsrc = "";
	$assigned_to = "";
	$region2 = "";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

				$queryCases = array("customer_name","bcity","bphone","description","bstate","ageto","industry","lsrc","assigned_to");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						case "customer_name":
						$customer_name = $v;
						$queryCondition .= "customer_name LIKE '%" . $v . "%'";
						break;
						
						case "bstate":
						$bstate = $v;
						$queryCondition .= "bstate LIKE '" . $v . "%'";
						break;
						
						case "ageto":
						$ageto = $v;
						$queryCondition .= "age <= '" . $v . "%'";
						break;
						
						
						case "bphone":
						$bphone = $v;
						$queryCondition .= "bphone LIKE '" . $v . "%'";
						break;
						
						case "bcity":
						$bcity = $v;
						$queryCondition .= "bcity LIKE '" . $v . "%'";
						break;
						
						case "description":
						$description = $v;
						$queryCondition .= "description LIKE '" . $v . "%'";
						break;
						
						case "industry":
						$industry = $v;
						$queryCondition .= "industry LIKE '" . $v . "%'";
						break;
						
						case "lsrc":
						$lsrc = $v;
						$queryCondition .= "lsrc LIKE '" . $v . "%'";
						break;
						
						case "assigned_to":
						$assigned_to = $v;
						$queryCondition .= "assigned_to LIKE '" . $v . "%'";
						break;
						
						
						
						
				}
			}
		}
	}
	
	
	
	
	
	
	
	if($queryCondition!='') { 
	$orderby = "  ORDER BY customer_name ASC  "; 
	$sql = "SELECT * FROM customer_master " . $queryCondition ."";
	} else {
		$sql = "SELECT * FROM customer_master ORDER BY customer_name ASC";
	}
	
	$resultnote = mysql_query($sql);

	$num_rownote = mysql_num_rows($resultnote);

	//echo $sql ;
	$href = 'view_all_accounts.php';					
		
	$perPage = 50; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(!empty($result)) {
		$result["perpage"] = showperpage($sql, $perPage, $href);
	}
?>  <div class="content-page">
    <div class="content">
      <div class="container">
	  <div class="row">
          <div class="col-sm-12">
            <div class="page-header-title">
            <button type="button" class="btn btn-dark waves-effect waves-light" onclick="location.href='qtn_status.php'">BACK </button>
              <div class="clearfix"></div>
            </div>
          </div>
        </div>
	  
	  <form name="chkForm" id="chkForm" action="view_all_accounts.php"  method="post" >
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3 class="panel-title">Search Account</h3></div>
                                <div class="panel-body">
                                    <div class="row">
                                                    <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Invoice No. </label>
                                                          <input type="text" placeholder="INV No." name="search[inv_no]" class="form-control" value="<?php echo $inv_no; ?>"	/>
                                                    </div>
													</div>
													
												 <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Account Name</label>
                                                          <input type="text" placeholder="Account Name" name="search[customer_name]" class="form-control" value="<?php echo $customer_name; ?>"	/>
                                                    </div>
													</div>
													
													 <div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>City</label>
                                                       <input type="text" placeholder="City" name="search[bcity]" class="form-control" value="<?php echo $bcity; ?>"	/></div>
													</div>
													
                                                    	<div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>Phone</label><input type="text" placeholder="Phone" name="search[bphone]" class="form-control" value="<?php echo $bphone; ?>"	/>
														
                                                    </div></div>
													<div class="col-sm-3 col-xs-12"><div class="form-group">
                                                        <label>State</label><input type="text" placeholder="State" name="search[bstate]" class="form-control" value="<?php echo $bstate; ?>"/>
                                                    </div>
                                                    </div>
											
                                                    
													
													
                                                    
                                                    <div class="col-sm-12 col-xs-12">
                                           
                                            <div class="m-t-20">
                                                    <div class="form-group">
                                                        <div>
                                                            <button type="submit" class="btn btn-primary waves-effect waves-light"> Submit </button>
							<input type="reset" class="btn btn-primary " value="Reset" onClick="window.location='view_all_accounts.php'">
															
                                                           
                                                        </div>
                                                    </div>
                                               
                                            </div>
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
					
					
					</form>
        
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-primary">
              <div class="panel-heading">
                <h3 class="panel-title">View all Account</h3>
              </div>
              <div class="panel-body">
                <table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                  <thead>
                    <tr>
					    <th>Account Name</th>
								       <th >Payment</th>
									   <th >Company Type</th>
									   <th>City / State</th>
									   <th>Email</th>
								      
								       <th>Contact Person</th>
									    <th>Contact No.</th>
								        <th>&nbsp;</th>
										<th>&nbsp;</th>
                    </tr>    
                  </thead>
                  <tbody>
                    <?php
					$i=1;
					
						
foreach($result as $k=>$v) {
						if(is_numeric($k)) {
						$dir_inv_id=$result[$k]["dir_inv_id"];
												$type_note=$result[$k]["type_note"];

?>	

	
		 <tr>
 <td><a href="view_account.php?customer_id=<?php echo $result[$k]["customer_id"] ?>&&id=<?php echo $result[$k]["id"] ?>" class="pointer center">
 
  <?php echo  wordwrap($result[$k]["customer_name"],15,"<br>\n");?>
 
 </a></td>
    <td>
<?php
$querytax = "select * from tax_servicetax where customer_id = '".$result[$k]["customer_id"]."'";
//echo $querytax;
$resulttax = mysql_query($querytax) or die(mysql_error());
$num_rows1 = mysql_num_rows($resulttax);
if($num_rows1>='1'){
?>
<a href="payment_entry.php?customer_id=<?php echo $result[$k]["customer_id"] ?>" class="pointer center">Payment Entry</a>

<?php

}	
?>	</td>
	
	<td><?php echo $result[$k]["comptype"]; ?>
	
	
	 <?
$i=1;
$query1 = "select * from third_customer_master where id = '".$result[$k]["id"]."' and customer_id = '".$result[$k]["customer_id"]."' and  customer_id != ''";
//echo $query1;
$result1 = mysql_query($query1) or die(mysql_error());
$num_rows1 = mysql_num_rows($result1);

while($row=mysql_fetch_array($result1))
		{  
$name = $row["party_name"];	

?>
	<br><?php echo $name;?>
	<? } ?></td>
	<td><?php echo $result[$k]["bcity"]; ?><br><?php echo $result[$k]["bstate"]; ?></td>
	<td><?php echo $result[$k]["bemail"]; ?></td>
  
  
<td>

    <? 
$i=1;
$query1 = "select * from contact_person where customer_id = '".$result[$k]["customer_id"]."' and  customer_id != ''";
//echo $query1;
$result1 = mysql_query($query1) or die(mysql_error());
$num_rows1 = mysql_num_rows($result1);
while($row=mysql_fetch_array($result1))
		{  
$name = $row["name"];	

?>
	<br><?php echo $name;?>
	<? } ?></td>
	<td>

    <? 
$i=1;
$query1 = "select * from contact_person where customer_id = '".$result[$k]["customer_id"]."' and customer_id != ''";
//echo $query1;
$result1 = mysql_query($query1) or die(mysql_error());
$num_rows1 = mysql_num_rows($result1);
while($row=mysql_fetch_array($result1))
		{  
$mobile_no = $row['mobile_no'];

?>
	<?php echo $mobile_no;}?>, <? echo $result[$k]["bphone"];?>  </td>
	
				   <td><a href="makedirect_credit_note.php?customer_id=<? echo $result[$k]["customer_id"];?>" class="btn btn-primary waves-effect waves-light">Make Credit Note</a></td>

    <td><a href="contact_person_add2.php?customer_id=<?php echo $result[$k]["customer_id"]?>" target="_blank"  class="btn btn-danger waves-effect waves-light">Add Contact</a></td>
		 </tr>		
					<?php } }?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
   	<?php include 'footer1a.php';?>
