<?php	
	require_once("includes/config.php");
	$ac = new DbQuery();
    $ac->checkLogin();
    

	$html = '';
	$total = 0.00;
	
	 /****** POS DB Integration**********/
    define('DB_SERVER','localhost');
    define('DB_USER','pos');
    define('DB_PASS' ,'##1Samir##');
    define('DB_NAME', 'pos');
    $con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);

	// Check connection
	if (mysqli_connect_errno())
	{
		echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}
	


	       
	       /************* Products Rows *************/
	       $params = array(	
				'table' => 'product',
				'get'   =>'DISTINCT vendor',
			);

			$product_req = $ac->select($params,'get_data');
			
			    
			
		if($product_req){
		    $i=0;
		   foreach($product_req as $row){
    	       
    	      	/********** Fetch Vendor Rows ***************/
            	$contacts_query='SELECT * FROM `contacts` where type="supplier" and business_id=1 and id='.$row['vendor'];
            	$contacts_result = $con->query($contacts_query);
            	if(!$contacts_result) throw new exception(sprintf("Invalid query : %s", $contacts_query));
                
                $contacts_rows = array();
                if($contacts_result->num_rows <= 0){
                    echo "no users found !";
                }
                else{
            
                    $contacts_rows = $contacts_result->fetch_all(MYSQLI_ASSOC); //faster 
                }
                $name = '';
                if($contacts_rows){
                    foreach($contacts_rows as $contacts_row){
                        $name = $contacts_row['name'];
                    }
                }
    	       
        	      $html .=' <tr class="tr-shadow">
            	                <td>'.$name.'</td>
                	            <td> 
                                    <div class="table-data-feature justify-content-start">
                                        <a href="'.ROOT.'view.php?id='.$ac->mcEncrypt($row['vendor']).'&supplier='.$ac->mcEncrypt($name).'" class="item" data-toggle="tooltip" id="'.$row['vendor'].'" data-placement="top" title="View" target="_blank">
                                            <i class="zmdi zmdi-eye"></i>
                                        </a>
                                    </div>
                                </td>
            	            </tr>
                            <tr class="spacer"></tr>';
                    
               
                    
		   }
	    
    	}else{
    	   $html .='<tr class="tr-shadow text-center">
        	            <td colspan="8">No Record Found</td>
        	       </tr>';
    	}
	/**************** END Fetching **************/
	/******** END Integration**************/
   $page_body ='
            <div class="main-content">
                <div class="section__content ">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <!-- DATA TABLE -->
                                <form action="'.CALLBACK.'products.php" method="post">
                                    <input type="hidden" name="action" value="save-products-record" />
                                    <div class="d-flex m-b-35 m-b-35">
                                        <h3 class="title-5">Suppliers</h3>
                                        <h3 class="title-5 float-right">Total: <strong></strong></h3>
                                    </div>
                                            <div class="table-responsive table-responsive-data2">
                                            
                                                <table class="table table-data2">
                                                    <thead>
                                                        <tr>
                                                            <th>Name</th>
                                                            <th>Action</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        '. $html .' 
                                                    </tbody>
                                                </table>
                                           
                                            </div>
                                 </form>
                                <!-- END DATA TABLE -->
                            </div>
                        </div>
                    </div>
                </div>
            </div>';
        
    $title = 'Suppliers';
		$body = array(
		"pageTitle"=>$title,
		'content'=>$page_body,
		);
		echo $ac->buildFullPage($body);

?>

   