	<?php
	
	$cnt = 0;

	$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
	
	$c_shortdisc = 0;
	
	 include 'configi.php';

	
	$result = '';
	
	$cart_id	= 0;
	
	$stocklevel = 0;
	
	
	 include 'configi.php';
	 
 	$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
	
	$cart_id =  $_REQUEST['sales_id'];
//	echo "cart id is " . $cart_id;

//$cart_id=	45944;

	
	$prod_image_url1 = "";
	
	 include 'configi.php';

		$querystl="SELECT * from ".$_COOKIE['phxcrmclient_id']."_qtl where st_id = " . $cart_id;
//		echo $querystl;
		$resultstl=mysqli_query($conn, $querystl);

		while($rowstl=mysqli_fetch_array($resultstl)) { 

			$id_stl			 				= $rowstl['id_stl'];
			$prodserv_uid		 			= $rowstl['prodserv_uid'];
			$qty	 						= $rowstl['qty'];
		//	$qty_supp	 					= $rowstl['qty_supp'];
		//	$qty_bo	 						= $rowstl['qty_bo'];
		//	$qty_bo_pay						= $rowstl['qty_bo_pay'];
			$qtl_title 						= $rowstl['qtl_title'];
			$line_amount 					= $rowstl['line_amount'];
			$item_amount 					= $rowstl['item_amount'];
			$line_disc	 					= $rowstl['line_disc'];
			
			$qtl_catid					= $rowstl["qtl_catid"];
			$qtl_catname				= $rowstl["qtl_catname"];

		$qty_on_hand = 0;
			
		$queryprod="SELECT * from ".$_COOKIE['phxcrmclient_id']."_prod_search where sel_uid = " . $prodserv_uid;
//		echo $queryprod;
		$resultprod=mysqli_query($conn, $queryprod);

		while($rowprod=mysqli_fetch_array($resultprod)) { 

			$retail_price2			 				= $rowprod['price'];
			
			$main_uid								= $rowprod['main_uid'];
			
			$qty_on_hand			 				= $rowprod['qty_on_hand'];

	
			
		}
		
			$querystti="SELECT * from ".$_COOKIE['phxcrmclient_id']."_prod_search where sel_uid = ".$main_uid;

		//	echo $querystti;
			$resultstti=mysqli_query($conn, $querystti);
	
			while($rowstti=mysqli_fetch_array($resultstti)) { 

				$prod_image_url1			 			= $rowstti['prod_image_url1'];

			
			}
			
						
			$user_status = 1;
			$comp_stock_type = 1;
			
			
			$querymode="SELECT * from phx_userid where idphx_userid =  ".$_COOKIE['phxcrmclient_id'];

	//		echo $querystti;
			$resultmode=mysqli_query($conn, $querymode);
	
			while($rowmode=mysqli_fetch_array($resultmode)) { 
			
				$user_status			 			= $rowmode['user_status'];
				$comp_stock_type		 			= $rowmode['comp_stock_type'];
				$comp_pos_layout		 			= $rowmode['comp_pos_layout'];
				
				
				
			}
			
			
			// if demo mode change url
			
		//	if ($user_status == 0){
				
				//	$strfind = $_COOKIE['phxcrmclient_id']."_";
				//	echo $prod_image_url1;
				
				//	echo "<br>";
				//	$prod_image_url1 = str_replace("247", "94",$prod_image_url1);
					$prod_image_url1 = $prod_image_url1;
					
			//		echo 'https://app.phoenixcrm.co.nz/images/productsthumb/'.$prod_image_url1;
					
			//		exit;
					
					
				
	//		}
	
//	exit;
	
	if ($comp_pos_layout == "Compact"){
		
			
	$result = $result . '
	        <div style="border-top-left-radius: 0px; font-size: 12px; line-height: 12px; margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; padding-top: 0px; border-radius: 0px;" class="card cart-item mb-0">
          
            
                    <div class="cart-item-footer" style="line-height: 12px; margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; padding-top: 0px;box-shadow: 0;">
				
					                <a onclick="javascript: upd_cart('.$phxcrmclient_id.',\'delitem\','.$id_stl.',0)" style="padding: 5px" class="btn btn-outline-secondary btn-sm">X</a>
									<input readonly id="sku_'.$id_stl.'"  type="text" style="padding: 2px; display: inline; text-align: right; width: 70px; font-size: 13px; " class="form-control" value="'.htmlspecialchars($prodserv_uid).'" onchange="javascript: upd_item('.$phxcrmclient_id.',\'newitemvalue\','.$id_stl.', this.value)" />';
									
		
$result = $result . '<td>';
				
	include("configi.php");
$query2="select lu_prodcat_id, lu_code_descr from " . $_COOKIE['phxcrmclient_id'] . "_catcode order by lu_code_descr";
$result2=mysqli_query($conn, $query2);

$result = $result . "<select name='qtl_prod_catid_".$id_stl."' id = 'qtl_prod_catid_".$id_stl."' onchange='javascript:lineupdateqtl(".$id_stl.",0, this.options[this.selectedIndex].value, this.options[this.selectedIndex].text)' class='form-control' style='width: 160px; font-size: 13px;'>";

$result = $result . '<option>Select Category</option>';
while($row2=mysqli_fetch_array($result2)) {

if  ($row2['lu_prodcat_id'] == $qtl_catid)
{
	$result = $result . "<option value='" .  $row2['lu_prodcat_id'] . "' SELECTED>" . $row2['lu_code_descr'] . "</option>";
}
	else
	{
	$result = $result .  "<option value='" .  $row2['lu_prodcat_id'] . "'>" . $row2['lu_code_descr'] . "</option>";
}
}
$result = $result .  "</select>";

	$result = $result . '</td>';


								$result = $result . '<input type="text" id="title_'.$id_stl.'" style="width: 45%; font-size: 13px; padding-left: 2px; padding-right: 2px;" class="form-control" value="'.htmlentities(stripslashes(utf8_decode($qtl_title))).'" onchange="javascript:lineupdate('.$id_stl.',0,this.value)"  />
                           			<input id="item_amount_'.$id_stl.'"  type="text" style="display: inline; font-size: 13px; text-align: right; width: 90px; " class="form-control" value="'.$item_amount.'" onchange="javascript: upd_item('.$phxcrmclient_id.',\'newitemvalue\','.$id_stl.', this.value)" />
									<input id="line_disc_'.$id_stl.'" onchange="javascript: upd_disc('.$phxcrmclient_id.',\'newdisc\','.$id_stl.', this.value)"  type="text" style="display: inline; text-align: right; width: 60px; font-size: 13px; " class="form-control" value="'.$line_disc.'"/>
						

						<div style="width: 120px" class="stepper stepper-sm stepper-secondary">
                            
							<a onclick="javascript: upd_cart_qty('.$phxcrmclient_id.',\'subqty\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
							
                            <input type="text" id="qty_'.$id_stl.'" style="width: 80px; text-align: right;"  class="form-control" value="'.$qty.'" onchange="javascript: upd_cart_qty('.$phxcrmclient_id.',\'newqty\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_qty('.$phxcrmclient_id.',\'addqty\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
                        </div>';
												if ($comp_stock_type == 3){
						$result = $result . ' 

						<span>O/H:</span>
						<span id="count_all_today" class="badge badge-'.$stock_avail_badge.'">'.$qty_on_hand.'</span>
						<input id="stock_qty_'.$id_stl.'" readonly type="hidden" style="display: inline; text-align: right; width: 60px; color: '.$stock_avail_colour.'; background-color: transparent; border: none" class="form-control" value="'.$qty_on_hand.'"/>
										                        <span>Supply:</span>
												<div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_supp('.$phxcrmclient_id.',\'subqtysupp\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text" id="qty_supp_'.$id_stl.'" class="form-control" value="'.$qty_supp.'" onchange="javascript: upd_cart_supp('.$phxcrmclient_id.',\'newqtysupp\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_supp('.$phxcrmclient_id.',\'addqtysupp\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
                        </div>
						                        <span>Backorder:</span>
												<div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_bo('.$phxcrmclient_id.',\'subqtybo\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text" id="qty_bo_'.$id_stl.'" class="form-control" value="'.$qty_bo.'" onchange="javascript: upd_cart_bo('.$phxcrmclient_id.',\'newqtybo\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_bo('.$phxcrmclient_id.',\'addqtybo\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
							
                        </div>
						
												                        <span>BO Pay:</span>
												<div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_bo_pay('.$phxcrmclient_id.',\'subqtybopay\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text"  id="qty_bo_pay_'.$id_stl.'"  class="form-control" value="'.$qty_bo_pay.'" onchange="javascript: upd_cart_bo_pay('.$phxcrmclient_id.',\'newqtybopay\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_bo_pay('.$phxcrmclient_id.',\'addqtybopay\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
							
                        </div>
					

            ';
						}
				$result = $result . ' 
						<table>
						<tr>
						<td align="right">
						               <span style="text-align: right"> <strong class="price"> <input id="line_amount_'.$id_stl.'" readonly type="text" style="display: inline; text-align: right; width: 85px; color: rgb(30, 116, 253); background-color: transparent; border: none" class="form-control" value="'.$line_amount.'"/></strong></span>
						</td>
						</tr>
						</table>

            
                  
                </div>
  			</div>';
		
		
	$cnt = $cnt + 1;
		
	}else{
		
		
			
$result = $result . '
		     	            <div class="card cart-item mb-2">
                <div class="card-body">
                    <div class="in">

                        <img draggable="true" ondragstart="dragIt(event, '.$prodserv_uid.')" src="https://app.phoenixcrm.co.nz/images/productsthumb/'.$prod_image_url1.'" loading="lazy" onerror="this.onerror=null; this.src=\'https://app.phoenixcrm.co.nz/crm/images/noimage.png\'" alt="no image" class="imaged"/>
						
                        <div class="text">
                            <h3 class="title">'.$qtl_title.'</h3>';
							

							
							$stock_avail_colour = "green";
							
							$stock_avail_badge = "success";
							
							if ($qty > $qty_on_hand){
									$stock_avail_colour = "red";
									$stock_avail_badge = "danger";
							}else if ($qty == $qty_on_hand){
								$stock_avail_colour = "amber";
								$stock_avail_badge = "warning";
								
							}else{
								$stock_avail_colour = "green";
								$stock_avail_badge = "success";
								
							}
								
						
								
						$result = $result . ' 
              			<span>Item $</span><input id="item_amount_'.$id_stl.'"  type="text" style="display: inline; text-align: right; width: 120px; " class="form-control" value="'.$item_amount.'" onchange="javascript: upd_item('.$phxcrmclient_id.',\'newitemvalue\','.$id_stl.', this.value)" />
						<span>';
						$result = $result . ' 
						</span>Discount %<input id="line_disc_'.$id_stl.'" onchange="javascript: upd_disc('.$phxcrmclient_id.',\'newdisc\','.$id_stl.', this.value)"  type="text" style="display: inline; text-align: right; width: 80px; " class="form-control" value="'.$line_disc.'"/>

                        </div>
                    </div>
                    <div class="cart-item-footer">
                        <div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_qty('.$phxcrmclient_id.',\'subqty\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text" id="qty_'.$id_stl.'"  class="form-control" value="'.$qty.'" onchange="javascript: upd_cart_qty('.$phxcrmclient_id.',\'newqty\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_qty('.$phxcrmclient_id.',\'addqty\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
                        </div>';
												if ($comp_stock_type == 3){
						$result = $result . ' 

						<span>O/H:</span>
						<span id="count_all_today" class="badge badge-'.$stock_avail_badge.'">'.$qty_on_hand.'</span>
						<input id="stock_qty_'.$id_stl.'" readonly type="hidden" style="display: inline; text-align: right; width: 60px; color: '.$stock_avail_colour.'; background-color: transparent; border: none" class="form-control" value="'.$qty_on_hand.'"/>
										                        <span>Supply:</span>
												<div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_supp('.$phxcrmclient_id.',\'subqtysupp\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text" id="qty_supp_'.$id_stl.'" class="form-control" value="'.$qty_supp.'" onchange="javascript: upd_cart_supp('.$phxcrmclient_id.',\'newqtysupp\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_supp('.$phxcrmclient_id.',\'addqtysupp\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
                        </div>
						                        <span>Backorder:</span>
												<div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_bo('.$phxcrmclient_id.',\'subqtybo\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text" id="qty_bo_'.$id_stl.'" class="form-control" value="'.$qty_bo.'" onchange="javascript: upd_cart_bo('.$phxcrmclient_id.',\'newqtybo\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_bo('.$phxcrmclient_id.',\'addqtybo\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
							
                        </div>
						
												                        <span>BO Pay:</span>
												<div class="stepper stepper-sm stepper-secondary">
                            <a onclick="javascript: upd_cart_bo_pay('.$phxcrmclient_id.',\'subqtybopay\','.$id_stl.',0)"  class="stepper-button stepper-down">-</a>
                            <input type="text"  id="qty_bo_pay_'.$id_stl.'"  class="form-control" value="'.$qty_bo_pay.'" onchange="javascript: upd_cart_bo_pay('.$phxcrmclient_id.',\'newqtybopay\','.$id_stl.', this.value)"  />
                            <a onclick="javascript: upd_cart_bo_pay('.$phxcrmclient_id.',\'addqtybopay\','.$id_stl.',0)" class="stepper-button stepper-up">+</a>
							
                        </div>
						                <div class="mt-1"></div>

            ';
						}
				$result = $result . ' 
						<table>
						<tr>
						<td align="right">
						               <span style="text-align: right"> <strong class="price"> Total $ <input id="line_amount_'.$id_stl.'" readonly type="text" style="display: inline; text-align: right; width: 85px; color: rgb(30, 116, 253); background-color: transparent; border: none" class="form-control" value="'.$line_amount.'"/></strong></span>
						</td>
						</tr>
						</table>
                        <a onclick="javascript: upd_cart('.$phxcrmclient_id.',\'delitem\','.$id_stl.',0)" class="btn btn-outline-secondary btn-sm">Delete</a>
            
                    </div>
                </div>
  			</div>';
		
		
	$cnt = $cnt + 1;
	

		}
		


		}		

		if ($cnt == 0){
			echo "Your cart is empty";
		}

echo $result;


			
			?>