<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);

session_start();

if (isset($_SESSION["client_id"])){
}else{
	$_SESSION["client_id"] = 1;
	
	//get sales_id if logged in
	
	
}

if (isset($_COOKIE["t_cont_search_type"])){
	
	
}else{
	
	setcookie("t_cont_search_type", "All", time() + (20 * 365 * 24 * 60 * 60),'/');
	
}


if (isset($_COOKIE["t_cont_sel_id"])){
	
	
}else{
	
	setcookie("t_cont_sel_id", 0, time() + (20 * 365 * 24 * 60 * 60),'/');
	
}

?>
<!doctype html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="theme-color" content="#000000">
    <title>phoenixsoftware.co.nz. Shop POS solutions.</title>
    <meta name="description" content="phoenixsoftware.co.nz. Shop POS solutions.">
    <link rel="icon" type="image/png" href="../images/logo.png" sizes="32x32">
    <link rel="apple-touch-icon" sizes="180x180" href="../images/logo.png">


	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="manifest" href="manifest.json">

</head>

<body class=""  onload="">
    <link rel="stylesheet" href="../assets/css/style.min.css">
	<link rel="stylesheet" href="../css/jquery-ui.min.css">
	
<link rel="stylesheet" href="//cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">

	

	
	
    <!-- loader -->

    <!-- * loader -->

    <!-- App Header -->
    <div class="appHeader bg-primary scrolled is-active">
        <div class="left">
            <a href="#" class="headerButton" data-toggle="modal" data-target="#sidebarPanel">
                <ion-icon name="menu-outline"></ion-icon>
            </a>
        </div>

        <div  class="center">
		
		<?php
		
		//get 
		
		
		?>
	
	PhoenixCRM - Departments Screen


		</div>
    </div>
    <!-- * App Header -->

    <!-- Search Component -->

    <!-- * Search Component -->

    <!-- App Capsule -->
    <div id="appCapsule" class="col-md-12" >
<center>

    <div class="row" style="height: 900px;" >
	


        <div style="border: solid 1px; border-color: #6c757d"  class="col-md-6">
                 <div style="" class="section mt-6 mb-6"><br>
				 
				 
				 
				           <div class="tab-pane fade show active" id="pilled" role="tabpanel">

                <div class="section full mt-1">
                  
                    <div class="wide-block pt-2 pb-2">

                        <ul class="nav nav-tabs lined" role="tablist">
                            <li class="nav-item">
                                <a id="tabcurrentsale" class="nav-link active" data-toggle="tab" href="#home" role="tab">
                                    Search Department
                                </a>
                            </li>

        
         
                        </ul>
                        <div class="tab-content mt-2">
                            <div class="tab-pane fade show active" id="home" role="tabpanel">
                                
                <div class="section full mt-1">
                    
                    <div class="wide-block pt-2 pb-2">
                               <form class="search-form">
            <div  class="form-group searchbox">
                <input type="text" tabindex="1" id="tagsdeptsearch"  class="form-control" placeholder="Search Department ..." >
                <i class="input-icon">
                    <ion-icon name="search-outline"></ion-icon>
                </i>
				<button id="createcontact" style="display: inline" type="button" class="btn btn-secondary" data-toggle="modal" data-target="#DialogCr8">Create</button>
            </li>
            </div>
        </form>        
		
            <div class="accordion" id="accordionExample2">

                <div class="item">
					<div style="float: left" class="">

                        <button style="color: blue; text-decoration: underline;" onclick="clear_search()" class="btn collapsed" type="button" >
                           &nbsp; Clear
                        </button>
						</div>
					<div style="display: none; float: right" class="accordion-header">
                        <button style="color: blue; text-decoration: underline;" class="btn collapsed" type="button" data-toggle="collapse" data-target="#accordion01">
                            Advanced Search
                        </button>
                    </div>
                    <div id="accordion01" class="accordion-body collapse" data-parent="#accordionExample2">
                        <div class="accordion-content">
            <div class="wide-block pt-2 pb-2">

                Cust
                <div class="custom-control custom-radio d-inline">
                    <input onclick="javascript: set_search('t_cont_search_type', 'Customer')"  type="radio" id="customRadioa1" name="customRadioInline" class="custom-control-input">
                    <label class="custom-control-label p-0" for="customRadioa1"></label>
                </div>
                Supplier
                <div class="custom-control custom-radio d-inline">
                    <input onclick="javascript: set_search('t_cont_search_type', 'Supplier')" type="radio" id="customRadioa2" name="customRadioInline" class="custom-control-input">
                    <label class="custom-control-label p-0" for="customRadioa2"></label>
                </div>
                All
                <div class="custom-control custom-radio d-inline">
                    <input onclick="javascript: set_search('t_cont_search_type', 'All')" <?php if ($_COOKIE['t_cont_search_type'] == "All"){ echo "checked";} ?> type="radio" id="customRadioa3" name="customRadioInline" class="custom-control-input">
                    <label class="custom-control-label p-0" for="customRadioa3"></label>
                </div>
            </div>
                        </div>
                    </div>
                </div>
		

        </div>
		
		

			<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
			<th style="width: 70px">ID:</th>
			<th style="width: 200px">Department:</th>
                <th style="width: 150px">Status:</th>

            </tr>
        </thead>
      </table>


        <!-- Discount Action Sheet -->

        <!-- * Discount Action Sheet -->

                    </div>
                </div>
                            </div>

                        </div>

                    </div>
                </div> </div>
				 
				 




        </div>
        </div>



        <div style="border: solid 1px; border-color: #6c757d; margin-top: 0px;padding-top: 0px;"  class="col-md-6">

 <div style="margin-top: 0px; padding-top: 0px;"  class="section mt-6 mb-6">
                  <div style="" class="section mt-6 mb-6"><br>
				 				     <div class="extraHeader p-0">
        <ul class="nav nav-tabs lined" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#quickpicks" role="tab">
                    Show Department
                </a>
            </li>

            <li class="nav-item">
					<button id="openstafflogin" style="display: inline" type="button" class="btn btn-primary" data-toggle="modal" data-target="#DialogContEdit">Edit</button>
            </li>
        </ul>
    </div>
	
	            <div class="tab-pane fade show active" id="quickpicks" role="tabpanel">

                <div class="section full mt-1">
                    
                    <div class="wide-block pt-2 pb-2">


<div id="divcontview" style="height: 660px; overflow-y: scroll;"  >

</div>



        <div class="section full mt-3">

            <div class="wide-block p-0 pt-2 pb-2">
                <!-- Story Blocks -->


            <div id="divshowquickpickitems" class="wide-block pt-3 pb-3">

				



            </div>


                <!-- Story Blocks -->
            </div>

        </div>
		

</div>


        <!-- Discount Action Sheet -->

        <!-- * Discount Action Sheet -->


                    </div>
                </div>

            </div>

	
            <!-- videos tab -->

            <!-- * videos tab -->

	            <!-- sounds tab -->
            <div class="tab-pane fade" id="sounds" role="tabpanel">

                <div class="section full mt-1">
                    <div class="section-title">Sounds</div>
                    <div class="wide-block pt-2 pb-2">
                        This is an example text.
                    </div>
                </div>

            </div>



        <div class="section full mt-2">
            <div class="section-title"></div>
            <div  class="wide-block pt-2 pb-2">
				

				 
            </div>
        </div>

        <!-- Dialog Form -->
		
		<div class="modal fade" id="DialogContEdit" tabindex="-1" role="dialog" aria-labelledby="divcontedit" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">

                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Edit Department Details</h5>
						 <a href="javascript:;" data-dismiss="modal">Close</a>
                    </div>
                    <form>
                        <div id="divcontedit" style="height: 700px; overflow-y: scroll" class="modal-body text-left mb-6">


                        </div>
                        <div class="modal-footer">
                            <div class="btn-inline">
                            
                                <button  type="button" data-dismiss="modal" class="btn btn-text-primary">CLOSE</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- * Dialog Form -->

		</div>
		</div>

		
		
        </div>


</div>




        <!-- app footer -->
        <div  class="section mt-6 mb-6">


		<center>	<small>
 </center>
	<?	
					 	 include '../php/configi.php';
						 
		//	echo "cookie".$_COOKIE['phxcrmclient_id'];			 
						 
						 
	if (isset($_COOKIE['phxcrmclient_id'])){
		 $phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
		 
		 		$queryclient="SELECT * from ".$_COOKIE['phxcrmclient_id']."_client where dept_id = " . $phxcrmclient_id;
	//	echo $queryprod;
		$resultclient=mysqli_query($conn, $queryclient);

		while($rowclient=mysqli_fetch_array($resultclient)) { 

			$comp_name			 				= $rowclient['comp_name'];
			
		}

?>

<?

//echo $_COOKIE['phxcrmclient_id'];

	}else{
		
		
	//	echo $_COOKIE['phxcrmclient_id'];

		
	}
	?>
	<br>

     
            <div class="footer-title">
			<center>
                Copyright © phoenixsoftware.co.nz 2021.<br> All Rights Reserved.
            </center>
			</div>
 


        </div>
        <!-- * app footer -->

    </div>
    <!-- * App Capsule -->
<div class="modal fade dialogbox" id="DialogBasic" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Apply Payment:</h5>
                    </div>
                    <div class="modal-body">
                      

						
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-primary" data-dismiss="modal">OK</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		

		
		        <div class="modal inset fade action-sheet ios-add-to-home" id="ios-add-to-home-screen" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add to Home Screen</h5>
                        <a href="javascript:;" class="close-button" data-dismiss="modal">
                            <ion-icon name="close"></ion-icon>
                        </a>
                    </div>
                    <div class="modal-body">
                        <div class="action-sheet-content text-center">
                            <div class="mb-1"><img src="../images/logo.png" alt="image" class="imaged w48">
                            </div>
                            <h4>phoenixsoftware.co.nz</h4>
                            <div>
                                Install phoenixsoftware.co.nz on your iPhone's home screen.
                            </div>
                            <div>
                                Tap the menu for your browser. Then tap Add to homescreen.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * iOS Add to Home Action Sheet -->
        <!-- Android Add to Home Action Sheet -->
        <div class="modal inset fade action-sheet android-add-to-home" id="android-add-to-home-screen" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add to Home Screen</h5>
                        <a href="javascript:;" class="close-button" data-dismiss="modal">
                            <ion-icon name="close"></ion-icon>
                        </a>
                    </div>
                    <div class="modal-body">
                        <div class="action-sheet-content text-center">
                            <div class="mb-1"><img src="../images/logo.png" alt="image" class="imaged w48">
                            </div>
                            <h4>phoenixsoftware.co.nz</h4>
                            <div>
                                Install phoenixsoftware.co.nz on your Android's home screen.
                            </div>
                            <div>
								Click menu for your browser then click "add app" or "install app".<br>If these options are not there - check for "add to home" option.<br> Once install is complete, go to your home screen and there should<br> be a phoenixsoftware.co.nz app installed. 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		
		        <div class="modal fade dialogbox" id="DialogCr8" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm you want to create department for</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="dispclientname">dispclientname</div>
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                            <a href="#" onclick="create_department()" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>- App Bottom Menu -->
    <div class="appBottomMenu">
        <a href="index.php" class="item active">
            <div class="col">
                <ion-icon name="home-outline"></ion-icon>
            </div>
        </a>


		
		
        <a href="javascript:;" class="item" data-toggle="modal" data-target="#sidebarPanel">
            <div class="col">
                <ion-icon name="menu-outline"></ion-icon>
            </div>
        </a>
    </div>
    <!-- * App Bottom Menu -->

    <!-- App Sidebar -->
	<?php include ('../php/sidebar.php'); ?>
    <!-- * App Sidebar -->

    <!-- welcome notification  -->
    <div id="notification-welcome" class="notification-box">
        <div class="notification-dialog android-style">
            <div class="notification-header">
                <div class="in">
                    <img src="../assets/img/icon/72x72.png" alt="image" class="imaged w24">
                    <strong>phoenixsoftware.co.nz</strong>
                    <span>just now</span>
                </div>
                <a href="#" class="close-button">
                    <ion-icon name="close"></ion-icon>
                </a>
            </div>
            <div class="notification-content">
                <div class="in">
                    <h3 class="subtitle">Welcome to phoenixcrm.co.nz</h3>
                    <div class="text">
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
        <div id="toast-login-successful" class="toast-box toast-bottom bg-success">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Login Successful</center>
                </div>
            </div>
        </div>
				        <div id="toast-login-failed" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Login Failed. Please try again</center>
                </div>
            </div>
        </div>

    <!-- * welcome notification -->

    <!-- ///////////// Js Files ////////////////////  -->
    <!-- Jquery -->
    <script src="../assets/js/lib/jquery-3.4.1.min.js"></script>
	
	

	<script src="../js/jquery-ui.min.js"> </script>
	
    <!-- Bootstrap-->
    <script src="../assets/js/lib/popper.min.js"></script>
    <script src="../assets/js/lib/bootstrap.min.js"></script>
    <!-- Ionicons -->
    <script type="module" src="https://unpkg.com/ionicons@5.2.3/dist/ionicons/ionicons.js"></script>
  
    <!-- Base Js File
    <script src="../assets/js/base.js"></script> -->

    
	<script src="//cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
    
	
	<!-- Owl Carousel -->
	
	
    <script src="../assets/js/plugins/owl-carousel/owl.carousel.min.js"></script>
    <!-- jQuery Circle Progress -->
    <script src="../assets/js/plugins/jquery-circle-progress/circle-progress.min.js"></script>

    <script>
	
	
	function getCookie(cname) {
  let name = cname + "=";
  let ca = document.cookie.split(';');
  for(let i = 0; i < ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}




$(document).ready(function(){

	$("#tagsdeptsearch").autocomplete({

		source: "../php/searchdept.php",
		cacheLength: 0,
		minLength: 1,
		select: function (event, ui) {
			
			setCookie("t_dept_sel_id", ui.item.value, 365);
		 
			$('#example').DataTable().ajax.reload();
			
		//	get_contact(ui.item.uid);
								
		//	get_contact_edit(ui.item.uid);


		},
		}).data("ui-autocomplete")._renderItem = function (ul, item) {
			var highlighted = item.label.split(this.term).join('<strong>' + this.term +  '</strong>');
			let txt = String(item.value).replace(new RegExp(this.term, "gi"),"<b>$&</b>");
			return $("<li></li>")
				.data("item.autocomplete", item)
				.append("<a span style='font-family: \'Helvetica Neue\', Helvetica, Arial'>" + txt + "</a>")
				.appendTo(ul);

		};

$("#tagsdeptsearch").keydown(function(event){
    if(event.keyCode == 13) {

      if($("#tagsdeptsearch").val().length==0) {
          event.preventDefault();
		  
		//  alert ($("#tagsdeptsearch").val());
		  
          return false;
      }else{
		   event.preventDefault();
		   
		   // go get item and if found add to cart.
		   
		   var search_string = $("#tagsdeptsearch").val();
		   
		   setCookie("t_dept_sel_id", search_string, 365);
		 
			$('#example').DataTable().ajax.reload();
		
	  }
    }
 });

});


 
 

	function clear_search(type, value){
	
		document.getElementById("tagsdeptsearch").value = "";
		
		setCookie("t_cont_sel_id", 0, 365);
		 
		$('#example').DataTable().ajax.reload();
	
	}
	


    </script>

    <script>
	
	$('#DialogCr8').on('shown.bs.modal', function () {
	
//	alert ("cash");



	var tagsdeptsearch = document.getElementById("tagsdeptsearch").value;
	
	
	if (tagsdeptsearch == ""){
		
	 alert ("Please enter a value for department"); 

		$('#DialogCr8').modal('hide');	 
	}



	document.getElementById("dispclientname").innerHTML = tagsdeptsearch;

	
	
	
	

}) 
	

	function load_cart(){
		
//		alert ("load");
			//alert ("load " + cart_id);
			
			
		//get cookie if exists

		
			
		
			
					
		document.getElementById("divcartitems").innerHTML = "loading ...";
		document.getElementById("divcarttotals").innerHTML = "";

	//	alert ("in function "+value);
		
		var type = "category";
		
	//	var cat_id = 


		$.ajax({
				url: 'php/getcartitems.php',
				type: 'post',
				async: 'true',
		//		data: {"client_id" : client_id},
				success: function(data) {
					
				//	alert (data);
					

							document.getElementById("divcartitems").innerHTML = data;
							
							load_cart_totals();
							$('#tagsdeptsearch').focus();
							
				//			alert ("setfocus done");
			

				}
			});



		
			
		
	}
	
		function load_cart_totals(){
		
			//alert ("load " + cart_id);
			
					

		

	//	alert ("in function "+value);
		
		var type = "category";
		
	//	var cat_id = 


		$.ajax({
				url: 'php/getcarttotals.php',
				type: 'post',
				async: 'true',
		//		data: {"cart_id" : cart_id},
				success: function(data) {
					
				//	alert (data);
					

							document.getElementById("divcarttotals").innerHTML = data;

				}
			});



		
			
		
	}
	
					
	function upd_cart(client_id, cart_function, cart_uid){
		
		var newqty = 0;
		
		// add item
		
		$.ajax({
				url: 'php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
				//	var new_item_amount   	= "$"+obj.new_item_amount;
					
					if (phx_result == ""){
						
						load_cart();			

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
	
						
	function upd_cart_qty(client_id, cart_function, cart_uid, newqty){
		
	//	alert ("init");
	

		var newqty = newqty;
		
	//	alert (newqty);
		
		
	//	if (newqty < 1){
			
	//		toastbox('toast-qty0', 2000)
		
	//		return false;
			
	//	}
		
	//	alert (qty);
		
		
		// add item
		
		$.ajax({
				url: 'php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var new_item_amount   	= "$"+obj.new_item_amount;
					
					if (phx_result == ""){
						
								//update item line qty
							var item_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(item_amount_field).value = new_item_amount;
								
							load_cart_totals();
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
		function make_order(cart_id, disc){
			
			var cart_id = cart_id;
		
			var totalitems = document.getElementById("totalitems").value;
	
			// do da validations
			
	//		alert (totalitems);
	
	//		if (disc == 1){
				
				//then friends and family so no minimum order qty
				
		//	}else{
	//	
			//	if (totalitems >= 60){
		//
	//			}else{
//	
	//				toastbox('toast-1', 2000);	
	//					
	//				return false;
	//			
	//			}
	//			
	//		}


			window.location.href = "make_order.php?sales_id="+cart_id;
		

			

	}
	

	
	$('#DialogContEdit').on('shown.bs.modal', function () {

	//alert ("shown");
//		$('#tagsstaffpw').value = "";
	//	$('#Bullets').value = "";
	//	clear_charp();
		$('#comp_name_edit').focus();
		
	//	alert ("done");
	

}) 


	$('#DialogContEdit').on('hide.bs.modal', function () {

	//alert ("shown");
//		$('#tagsstaffpw').value = "";
	//	$('#Bullets').value = "";
	//	clear_charp();
	//	$('#comp_name_edit').focus();
		
	//	alert ("done");
	
		 $('#example').DataTable().ajax.reload( null, false )

}) 


function exec_openstafflogin(){
	
	document.getElementById("openstafflogin").click();
	alert ("clicked");
	
	
}


function add_charp(val){
	
	var cur_val = document.getElementById("tagsstaffpw").value;

	var new_val = String(cur_val)+String(val);
	
	
	var pin_length = new_val.length;
	
//	alert (pin_length);
	
	if (pin_length == 0){
		new_val_disp = "";	
	}else if (pin_length == 1){
		new_val_disp = "*";	
	}else if (pin_length == 2){
		new_val_disp = "**";	
	}else if (pin_length == 3){
		new_val_disp = "***";	
	}else if (pin_length == 4){
		new_val_disp = "****";	
	}else{

		return false;
		
	}
	
	document.getElementById("tagsstaffpw").value = new_val;
	
	document.getElementById("Bullets").value = new_val;

	document.getElementById('Bullets').value=new_val.replace(/(.)/g,'•');


	
}






function clear_charp(){
	
//	alert ("clear");
	

	var new_val = "";

	document.getElementById("tagsstaffpw").value = new_val;
	document.getElementById("Bullets").value = new_val;


	document.getElementById("tagsstaffpw").focus();


}



function login_staff(){
	

	var new_val = document.getElementById("tagsstaffpw").value;
	
	//alert (new_val);
	
	
					$.ajax({
					url: 'php/staff_login.php',
					type: 'post',
					async: 'true',
					data: {"new_val" : new_val},
					success: function(data) {
					
					//	alert ("data"+data);

						var obj = JSON.parse( data );
					
						var phx_result 	  		= obj.phx_result;
						var phx_message 	  	= obj.phx_message;
					
						if (phx_message == "valid"){

							//if valid then get userid and close dialog
							var staff_id = getCookie("phxcrmuserid");
							sessionStorage.setItem("phxcrmuserid", staff_id);
							document.getElementById("tagsstaffpw").value = "";
						
							$('#DialogContEdit').modal('hide');

							load_cart();
							
						//	$('#tagsdeptsearch').focus();
							
					//		get_quickpick_list();
							
							toastbox('toast-login-successful', 2000);
							

						}else{
							document.getElementById("tagsstaffpw").value = "";
							toastbox('toast-login-failed', 2000);

						}

					}
				});
				
			

//	alert ("login"+new_val);
	
	
}
function logout_staff(){



	window.location.replace("logout.php");

//	alert ("logout staff");

	
}


		
	function add_cart(uid, type){
	
	var qty = 1;
		
		// add item
		
		$.ajax({
				url: 'php/additem.php',
				type: 'post',
				async: 'false',
				data: {"uid" : uid, "qty" : qty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
					document.getElementById("tagsdeptsearch").value = "";
					
					load_cart();
					
					

					
					
				//	if (data == "successful"){
						
				//				toastbox('toast-4', 2000);			

				//	}else{
												
				//		alert ("An error ocurred adding item "+data);
					
				//	}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
	function dragItqp(theEvent, prodserv_uid) {
 //tell the browser what to drag
	theEvent.dataTransfer.setData("Text", theEvent.target.id);
	sessionStorage.setItem("sel_qp_id", prodserv_uid);
	
	

 
}


function dropItqp(theEvent) {
	
//	alert ("drop");
	
	theEvent.preventDefault();
	
	var sel_prod_id = sessionStorage.getItem("sel_qp_id");
	
	
	//do something
	
		if (sel_prod_id === null){
			
		//	nothing dragged that is expected;
			
		}else{
			
			// call ajax and add item to quickpick
			
			var action = "rempick";
			
			$.ajax({
				url: 'php/updquickpick.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action},
				success: function(data) {
					
				//	alert (data);
					
					get_quickpick_list();
					
					//	var data = data.trim();
					
					//	document.getElementById("tagsdeptsearch").value = "";
					//	
					//	load_cart();

				}
			});

			
		}
	
	
	sessionStorage.removeItem("sel_qp_id");
	
	

	
//	console.log(theEvent);
	
	return false;
	
//get a reference to the element being dragged
var theData = theEvent.dataTransfer.getData("Text");
//get the element
var theDraggedElement = document.getElementById(theData);
//add it to the drop element
theEvent.target.appendChild(theDraggedElement);
//instruct the browser to allow the drop

}
	
function dragIt(theEvent, prodserv_uid) {
 //tell the browser what to drag
	theEvent.dataTransfer.setData("Text", theEvent.target.id);
	sessionStorage.setItem("sel_prod_id", prodserv_uid);
	
	

 
}

//function called when element drops
function dropIt(theEvent) {
	
	theEvent.preventDefault();
	
	var sel_prod_id = sessionStorage.getItem("sel_prod_id");
	
	
	//do something
	
		if (sel_prod_id === null){
			
		//	nothing dragged that is expected;
			
		}else{
			
			// call ajax and add item to quickpick
			
			var action = "addpick";
			
			$.ajax({
				url: 'php/updquickpick.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action},
				success: function(data) {
					
				//	alert (data);
					
					get_quickpick_list();
					
					//	var data = data.trim();
					
					//	document.getElementById("tagsdeptsearch").value = "";
					//	
					//	load_cart();

				}
			});

			
		}
	
	
	sessionStorage.removeItem("sel_prod_id");
	
	

	
//	console.log(theEvent);
	
	return false;
	
//get a reference to the element being dragged
var theData = theEvent.dataTransfer.getData("Text");
//get the element
var theDraggedElement = document.getElementById(theData);
//add it to the drop element
theEvent.target.appendChild(theDraggedElement);
//instruct the browser to allow the drop

}

	  function load_todays_sales() {
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		         document.getElementById("divtodaysalesreport").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "todaysalesshop.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}



	  function load_todays_sales_web() {
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		         document.getElementById("divtodaysaleswebreport").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "todaysalesweb.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}

function get_quickpick_list(){

			var sel_prod_id = 0;
			var action = "";

			$.ajax({
				url: 'php/getquickpick.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action},
				success: function(data) {
					
		//			alert (data);
					
					
						document.getElementById("divshowquickpickitems").innerHTML = data;

				}
			});	
	
}


function add_item_quickpick(uid){


			
			var qty = 1;
			
			$.ajax({
				url: 'php/additem.php',
				type: 'post',
				async: 'false',
				data: {"uid" : uid, "qty" : qty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
					document.getElementById("tagsdeptsearch").value = "";
					
					load_cart();
					
					

					
					
				//	if (data == "successful"){
						
				//				toastbox('toast-4', 2000);			

				//	}else{
												
				//		alert ("An error ocurred adding item "+data);
					
				//	}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});	
	
}

function load_contacts(){
	
//	alert ("load contacts");
	
}


			$(document).ready(function() {
				    var selected = [];
			var table =	$('#example').dataTable( {
					"jQueryUI": false,
					"bFilter": false,
					"processing": true,
					"bLengthChange": false,
					"serverSide": true,
					"select": true, 
					"order": [[ 1, "asc" ]],
					"ajax": "../datatables/sp_departments.php",
					        "fnDrawCallback": function (oSettings, json) {
							//	var length = $('#example').dataTable({bRetrieve: true}).fnGetData.length;
							var numrows = table.fnGetData().length;
							

//			alert( oSettings.aoData.count() );
//							alert (oSettings.aoData);
//console.log (oSettings);
							if (numrows == 0){
							}else{
								var data = $('#example').dataTable({bRetrieve: true}).fnGetData(0)[0];
								get_contact(data);
								
								get_contact_edit(data);
					
							}								
							
        }				} );

		$('#example tbody').on('click', 'tr', function () {
			var data = table.api().row( this ).data();
			
			get_contact(data[0]);
			
			get_contact_edit(data[0]);
			

		//	showclienttab(data[0]);
		   //     alert( 'You clicked on '+data[0]+'\'s row' );
		} );
		
	} );
	
	
	function get_contact(dept_id){
		
	//	alert (dept_id);
		
		
			var dept_id = dept_id;
			
	
			$.ajax({
				url: '../php/deptviewshop.php',
				type: 'post',
				async: 'false',
				data: {"dept_id" : dept_id},
				success: function(data) {
					
					var data = data.trim();
					
					document.getElementById("divcontview").innerHTML = data;
					
					
				}
			});	
		
		
	}
	
		function get_contact_edit(dept_id){
		
	//	alert (dept_id);
		
		
			var dept_id = dept_id;
			
	
			$.ajax({
				url: '../php/depteditshop.php',
				type: 'post',
				async: 'false',
				data: {"dept_id" : dept_id},
				success: function(data) {
					
					var data = data.trim();
					
					document.getElementById("divcontedit").innerHTML = data;
					
				}
			});	
		
		
	}
	
	function set_search(cookie_name, value){
		
		 setCookie(cookie_name, value, 365);
		 
		 $('#example').DataTable().ajax.reload();
		
		
	}
	
	function setCookie(cname, cvalue, exdays) {
  const d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  let expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"+ ";Secure";
}


			
	 function update_field_department(field_name, field_type, field_value, field_value2) {

	//		alert ("update"+field_name+field_type+field_value+field_value2);
			
		//	return false;
	//		alert ("update ");
			
			var dept_id			= document.getElementById('cv_dept_id').value;
			
		//	alert (uid_client);
			

	//		var element_je_job_outlet_name = document.getElementById('je_job_outlet_name')
			var outlet_id 			= 1;			
			var old_status			= "";

			var c_favcmts 			= "";

			
			//set defaults
			var c_favcmts = "";
			var c_popup = "";


								
			if (field_type == "inputcheck"){
	
				if (field_value === true){
					
					field_value = "Yes";
					
				}else{

					
					field_value = "No";
					
				}
				
				var field_type			= "inputcheck";
				var field_name1_db		= field_name;
				var field_name2_db		= "";
				var field_value1 		= field_value;
				var field_value2 		= "";

			}else{
	
				
				var field_type			= "input";
				var field_name1_db		= field_name;
				var field_name2_db		= "";
				var field_value1 		= field_value;
				var field_value2 		= "";

			}		
		
			var jobfields = {};

			jobfields.sales_id	 = 0;			
			jobfields.field_name = field_name;
			jobfields.field_type = field_type;
			jobfields.field_name1_db = field_name1_db;
			jobfields.field_name2_db = field_name2_db;
			jobfields.field_value1 = field_value1;
			jobfields.field_value2 = field_value2;
			jobfields.old_status = old_status;
			jobfields.dept_id = dept_id;
			jobfields.outlet_id = outlet_id;			
			
	//		alert (jobfields.field_name);
	//		alert ("about to ajax");


			
	//		alert (JSON.stringify(jobfields));
			
//			alert (c_favcmts);
			
			
			
			$.ajax({
				url: '../php/orderupddeptfield.php',
				type: 'post',
				data: {"jobfields" : JSON.stringify(jobfields)},
				success: function(data) {
				//	alert ("success"+data);
				//
				if (data == "Update Successful"){
				}else{
					alert ("Update failed error details are"+data);
				}
//				alert (data);

//					alert (field_name+data);
					// Do something with data that came back. 
				}
			});			
			
		//	alert (	jobfields.sales_id+jobfields.field_name+jobfields.field_type+jobfields.field_name1_db+jobfields.field_name2_db+jobfields.field_value1+jobfields.field_value2);


			
		 }


	
	function create_department(){
		
		var tagsprodcont = document.getElementById("tagsdeptsearch").value;

		
		// add item
		
		$.ajax({
				url: '../php/createdept.php',
				type: 'post',
				async: 'false',
				data: {"tagsprodcont" : tagsprodcont},
				success: function(data) {
				//	alert (data);
					
	                var obj = JSON.parse( data.trim() );
					
					if (obj.phx_result == ""){
						
					//	alert( obj.new_id);
						get_contact_edit( obj.new_id);
			
						document.getElementById("openstafflogin").click();
							
					}else{
						
						
					}

				}
			});
			
			
		
	}
	



    </script>

</body>

</html>