<style>
.table-checkable tr > td:first-child, .table-checkable tr > th:first-child {
  max-width: none;    
  padding-left: 5px;  
  text-align: left;
}
/* 
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
@media only screen and (max-width: 560px), (min-device-width: 568px) and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
	display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
	position: absolute;
	top: -9999px;
	left: -9999px;
}
tr {
	border: 0px solid #ccc;
}
td {
	/* Behave  like a "row" */
	border: none;
	/*border-bottom: 1px solid #eee; */
	position: relative;
	padding-left: 50%;
}
td:before {
	/* Now like a table header */
	position: unset; /*absolute causing issues*/
	/* Top/left values mimic padding */
	top: 6px;
	left: 6px;
	width: 45%;
	padding-right: 10px;
	white-space: nowrap;
}
/*
Label the data
*/
td:nth-of-type(1):before {content: "Shop";}
td:nth-of-type(2):before {content: "Email";}
td:nth-of-type(3):before {content: "Phone";}
td:nth-of-type(4):before {content: "Distance";}
td:nth-of-type(5):before {content: "Assign";}
}
@media only screen and (max-width: 480px), (min-device-width: 300px) and (max-device-width: 480px) {
	.table-checkable tr > td:first-child, .table-checkable tr > th:first-child {
	  max-width: 100%;  
	}	
}
</style>
<div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-bar">
                        <div class="page-title-breadcrumb">
                            <div class=" pull-left">
                                <div class="page-title">Assign Shop</div>
                            </div>
                            <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.php?page=home">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                </li>
                                <li><a class="parent-item" href="index.php?page=manage_purchase_order">Purchase Orders</a>&nbsp;<i class="fa fa-angle-right"></i></li><li class="active">Assign Shop</li>
                            </ol>
                        </div>
                    </div>
                    
	 <div class="row">
	 	
	 					<div class="col-md-12 col-sm-12">
                            <div class="card card-box">
                                <div class="card-head">
                                    <header>Order Summary</header>  
                                    <!--<div style="margin-left:20px;">
	                                	<a class="btn btn-info" href="index.php?page=view_purchase_order&id=<?php echo $orderId; ?>">Back</a>&nbsp;	  
	                                </div>-->                                                           
                                </div>
                                <div class="card-body" id="bar-parent1">                                	                      	                              		
                                		                                      	                          	                                	
                                    <form action="" id="form_staff_add" class="form-horizontal">                                    	
                                        <div class="form-body div-left">         
                                        	<div class="form-group row">
                                                <label class="control-label col-md-3">Task </label>
                                                <div class="col-md-4 pt-2">                                                    
                                                    <?php echo '#'.$taskId;?>
                                                </div>
                                            </div>          
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">Shop Name</label>
                                                <div class="col-md-4 pt-2">                                                    
                                                    <?php if($shopId>0){ ?>
                                                    	 <a href="index.php?page=view_purchase_partner&id=<?php echo $shopId; ?>"><?php echo getShopName($shopId); ?></a> 
												 	<?php }?>
                                                </div>
                                            </div>                     	                                        	 
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">Technician</label>
                                                <div class="col-md-4 pt-2">                                                    
                                                    <?php echo getTechnicianName($techId);?>
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">Technician Phone</label>
                                                <div class="col-md-4 pt-2">                                                    
                                                    <?php echo $techDetailRec['phone'];?>
                                                </div>
                                            </div>   
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">User</label>
                                                <div class="col-md-4 pt-2">                                                    
                                                    <?php echo getUserName($userId);?>
                                                </div>
                                            </div>
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">User Phone</label>
                                                <div class="col-md-4 pt-2">                                                    
                                                    <?php echo $userDetailRec['phone'];?>
                                                </div>
                                            </div>                                         
                                        </div>                                                                    
                                      	
                                    </form>
                                </div>
                            </div>
                        </div>
                        
                        
                        <div class="col-md-12 col-sm-12">
                            <div class="card card-topline-red">
                                <div class="card-head">
                                    <header>Products</header>
                                    <div class="tools">                                        
	                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
	                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
                                    </div>
                                </div>
                                <div class="card-body ">  
                                     <div style="height: 10px;clear: both;"></div>                                 
                                    <div <?php if(isset($_POST['category'])){ echo 'style="display: block;"';} else { echo 'style="display: none;"'; }?> id="add_div">
                                    	<?php if(isset($error) && $error!='') { ?> 
	                                	<div class="alert alert-danger"><?php echo $error; ?></div>
	                                	<?php } ?>  
                                    	<form action="" id="form_shop_add" class="form-horizontal" method="post">
	                                        <div class="form-body">	                                        	                                        	 
	                                            <div class="form-group row">
	                                                <label class="control-label col-md-3">Select Category<span class="required"> * </span></label>
	                                                <div class="col-md-4">                                                    
	                                                    <select name="category" id="category" onchange="getProducts()" >
	                                                    	<option value="">--Select Category--</option>
											              <?php if(mysqli_num_rows($categoryRs)>0){
											              	while($categoryRec = mysqli_fetch_array($categoryRs)){ 
											              		//get sub categories
											              		$subRs = mysqli_query($con, "SELECT id, name FROM tbl_product_categories WHERE parent_id = '".$categoryRec['id']."' ORDER BY name");	?>
											              	<option value="<?php echo $categoryRec['id']; ?>" <?php if(isset($_POST['category']) && $_POST['category']==$categoryRec['id']) { echo 'selected="selected"'; } else if(isset($resEdit['cat_id']) && $resEdit['cat_id']==$categoryRec['id']){ echo 'selected="selected"'; } ?> ><?php echo $categoryRec['name']; ?></option>
											              	<?php if(mysqli_num_rows($subRs)>0){ 
											              		while($categorySubRec = mysqli_fetch_array($subRs)){ ?>
											              			<option value="<?php echo $categorySubRec['id']; ?>" <?php if(isset($_POST['category']) && $_POST['category']==$categorySubRec['id']) { echo 'selected="selected"'; } else if(isset($resEdit['cat_id']) && $resEdit['cat_id']==$categorySubRec['id']){ echo 'selected="selected"'; } ?> ><?php echo '--'.$categorySubRec['name']; ?></option>
											              	<?php } } ?>
											              <?php } } ?>
											            </select>
	                                                </div>
	                                            </div>
	                                            <div class="form-group row">
	                                                <label class="control-label col-md-3">Select Product<span class="required"> * </span></label>
	                                                <div class="col-md-4">                                                    
	                                                    <select name="product" id="product" >
	                                                    	<option value="">--Select Product--</option>											              
											            </select>
	                                                </div>
	                                            </div>                                            	                                            
	                                            <div class="form-group row">
	                                                <label class="control-label col-md-3">Enter Quantity<span class="required"> * </span></label>
	                                                <div class="col-md-4">                                                    
	                                                    <input name="quantity" type="text" id="quantity" data-required="1" class="form-control" value="<?php if(isset($_POST['quantity'])) { echo htmlentities(($_POST['quantity']), ENT_QUOTES); } ?>"/>
	                                                </div>
	                                            </div>                                            
	                                        </div>                                        
	                                      	<div class="form-group">
	                                            <div class="offset-md-3 col-md-9">                                            	
	                                            		<button type="submit" name="add" class="btn btn-info">Add</button> 
	                                            </div>
	                                        </div>
	                                    </form>                                    	
                                    </div>                                    
                                    <?php if(isset($execProductDetails) && mysqli_num_rows($execProductDetails)>0) { ?>
                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
                                        <thead>
                                            <tr>                                                
                                                <th> S.No. </th>
                                                <th> Product </th>
                                                <th> Category </th>
                                                <th> Quantity </th>
                                                <th> Price </th>                                                
                                                <!--<th> Actions </th>-->
                                            </tr>
                                        </thead>
                                        <tbody>
                                        	<?php
                                        	if(isset($_GET['p']) && is_numeric($_GET['p']) && ($_GET['p'] > 1)) {
												$slNo = ($_GET['p']*30-29);
											} else {
												$slNo = 1;
											}
											$prodCatarray = array();
												while($resProductDetails = mysqli_fetch_array($execProductDetails)) {	
													$prodCatarray[] = $resProductDetails['cat_id']; ?>
                                            <tr class="odd gradeX">                                                
                                                <td><?php echo $slNo; ?></td>
                                                <td><?php echo getProductName($resProductDetails['product_id']); ?></td>
                                                <td><?php echo getProductCategory($resProductDetails['cat_id']); ?></td>
                                                <td><?php echo $resProductDetails['quantity']; ?></td>
                                                <td><?php echo $resProductDetails['price']; ?></td>                                                                                                
                                                <!--<td class="valigntop">
                                                    <div class="btn-group">
                                                        <button class="btn btn-xs deepPink-bgcolor dropdown-toggle no-margin" type="button" data-toggle="dropdown" aria-expanded="false"> Actions
                                                            <i class="fa fa-angle-down"></i>
                                                        </button>
                                                        <ul class="dropdown-menu pull-left" role="menu">                                                        	
                                                            <li>
                                                                <a  onclick="return confirm('Are you sure to delete this item?');" href="index.php?page=view_purchase_order&action=delete_product&del_id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Delete </a>
                                                            </li>                                                           
                                                        </ul>
                                                    </div>
                                                </td>-->
                                            </tr>
                                            <?php ++$slNo; } ?>                                            
                                        </tbody>
                                    </table>
                                    <div style="float: left; width: 25%;"> <?php echo $pageNums; ?> </div>
                                    <?php } else { ?>
                                    	<div class="alert alert-danger">Sorry! No Results Found.</div>					        		
					        		<?php }	?> 
                                </div>
                            </div>
                        
                        
                        <div class="col-md-12 pl-0 pr-0">
                            <div class="card card-topline-red">
                                <div class="card-head">
                                    <header>Assign Shop</header>
                                    <div class="tools">                                        
	                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
	                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
                                    </div>
                                </div>
                                <div class="card-body ">                                    
                                    <?php if(isset($_REQUEST['success'])){ ?><div class="alert alert-success"><?php echo urldecode($_REQUEST['success']); ?></div></div><?php } ?>
                                    <?php if(isset($execDetails) && mysqli_num_rows($execDetails)>0) { ?>
                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
                                        <thead>
                                            <tr>  
                                                <th> Shop </th>
                                                <th> Email </th>
                                                <th> Phone </th> 
                                                <th> Distance </th>                                                
                                                <th> Assign </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        	<?php
                                        	if(isset($_GET['p']) && is_numeric($_GET['p']) && ($_GET['p'] > 1)) {
												$slNo = ($_GET['p']*30-29);
											} else {
												$slNo = 1;
											}
											//make the product cat array to string so that we can use it in query
											if(isset($prodCatarray) && count($prodCatarray)>0){
												$prodCatarray = array_unique($prodCatarray);
												$catIdString = implode(',',$prodCatarray);
											} else {
												$catIdString = '';
											}
										
												while($resDetails = mysqli_fetch_array($execDetails)) {	
													//check if this shop is a partner in any of the categories in the order
													//echo "SELECT id FROM `tbl_partner_category` WHERE `partner_id` = '".$resDetails['id']."' AND `category_id` IN (".$catIdString.")";
													$partnerCatRs = mysqli_query($con, "SELECT id FROM `tbl_partner_category` WHERE `partner_id` = '".$resDetails['id']."' AND `category_id` IN (".$catIdString.")");
													if(mysqli_num_rows($partnerCatRs)>0){
														$isPartner = TRUE;
													} else {
														$isPartner = FALSE;
													}													
													?>
		                                            <tr class="odd gradeX">                                                   
		                                                <td>
		                                                	<?php if($isPartner){ ?>
		                                                	<div style="margin-top: -20px;position: absolute;width: 50px;"><img src="../images/partner-badge.png"></div>
		                                                	<?php } ?>
		                                                	<?php echo $resDetails['building_name']; ?>
		                                                </td>
		                                                <td><?php echo $resDetails['email']; ?></td>
		                                                <td><?php echo $resDetails['phone']; ?></td>
		                                                <td><?php echo number_format((float)$resDetails['distance'], 2, '.', '').' Km'; ?></td>                                                                                                
		                                                <td class="valigntop">                                                	                                               		
		                                                	<a class="btn btn-xs deepPink-bgcolor" href="index.php?page=view_purchase_order&id=<?php echo $orderId; ?>&action=assign&partner_id=<?php echo $resDetails['id']; ?>">Assign</a>
		                                                </td>
		                                            </tr>
                                            <?php ++$slNo; } ?>                                            
                                        </tbody>
                                    </table>                                    
                                    <?php } else { ?>
                                    	<div class="alert alert-danger">Sorry! No Results Found.</div>					        		
					        		<?php }	?> 
                                </div>
                            </div>
                        </div>
                    </div>
                    

</div>
</div>