<?php
	require_once("../mySQL.php");


		$json = array();
	
		
			//MVC Classes
			class Model{
				
					public $conn;
					public $userCode;
					public $jobCode;
					
					public function __construct(){
						$this->conn = null;
						$this->userCode = "";
						$this->jobCode = "";
						
					}
			}

			class View{
				
					private $model;
					private $controller;
					
					public function __construct($controller, $model){
						$this->controller = $controller;
						$this->model = $model;
						
					}
					
					public function pendingInvoicesView(){
						$jobCode = $this->model->jobCode;
						
						$sql = "SELECT * FROM `laundary_job` ORDER BY `job_id` DESC LIMIT 5 ";
						$result = $this->model->conn->query($sql);

						return $result;
					}
			}



			class Controller{
				
					private $model;
					
					public function __construct($model){
						$this->model = $model;
						
					}
					
					public function pendingInvoicesController($conn, $jobCode){
						$this->model->conn = $conn;
						$this->model->jobCode = $jobCode;
					}
					
			}


			//Call Controllers and Views
			$model = new Model();
			$controller = new Controller($model);
			$view = new View($controller, $model);
			//MVC Classes


?>
<style>
	/*body {
	  background: #232321;
	}
	h1 {
	  color: #fff;
	  padding: 10px 0;
	}*/
	.card {
	  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
	  transition: 0.3s;
	  border: none;
	  &:hover {
		box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.4);
	  }
	  a {
		color: initial;
		&:hover {
		  text-decoration: initial;
		}
	  }
	  .text-muted i {
		margin: 0 10px;
	  }
	}

/* side panel */ 
    .btn-squared-default
    {
        width: 60px !important;
        height: 60px !important;
        font-size: 10px;
		margin:5px;
    }

        .btn-squared-default:hover
        {
            border: 3px solid white;
            font-weight: 400;
        }

    .btn-squared-default-plain
    {
        width: 60px !important;
        height: 60px !important;
        font-size: 10px;
    }

        .btn-squared-default-plain:hover
        {
            border: 0px solid blue;
        }
		
/* side panel */ 
</style>

<div class="container-fluid">

<div class="row" id="searchResult">

		<div class="col-12">
		
		<!--
			<div class="card" style="width: 100%">
					<div class="row  m-0 p-0">
							<p class="btn btn-squared-default  btn-warning m-0 m-0"   onclick="updateQueryStringParameter('localhost:8012/qsolutionsug/washupPOS/', 'page', 'WalkInCustomer')">
								<i class="fa fa-arrow-left fa-4x"></i>
								
							</p>
							
							<div class="col" id="customerName">
								
							</div>
							<div class="col">
								<div class="row"  id="customerPhone">Tell</div>
								<div class="row"  id="customerEmail">Email</div>
							</div>
							<div class="col">
								<div class="row">Rank</div>
								<div class="row">last visit</div>
							</div>
							<div class="col">
								<div class="row">visit</div>
								<div class="row">points</div>
							</div>
					</div>
			</div>-->
			<div class="card mt-2" style="width: 100%">
			<div class=" mt-4" style="">
				<div class="" style="width: 100%">
					<div class="btn-toolbar " role="toolbar" aria-label="Toolbar with button groups">
					  <div class="btn-group mr-2" role="group" aria-label="First group">
						<button type="button" class="btn  btn-dark">Details</button>
						<button type="button" class="btn  btn-dark">Ready</button>
						<button type="button" class="btn  btn-dark">Picked</button>
						<button type="button" class="btn  btn-dark">All</button>
						<button type="button" class="btn  btn-dark">None</button>
					  </div>
					</div>
				</div>
			</div>
			<div class=" mt-4 mb-4" style="width: 100%">
	
					<table class="table table-bordered table-sm ">
						<thead class="thead-dark">
							<tr>
								<th>&nbsp;</th>
								<th>Invoice#</th>
								<th>Branch</th>
								<th>Tracker</th>
								<th>Pieces</th>
								<th>Inhouse</th>
								<th>Pick Date</th>
								<th>Ready Date</th>
								<th>Balance</th>
								<th>Discount</th>
								<th>Picked</th>
								<th>Paid</th>
								<th><i class="fa fa-external-link"></th>
								
							</tr>
						</thead>
						<?php 
						
						//Send Data to controller
						$jobCode = "";
						try{
							$controller->pendingInvoicesController($conn, $jobCode);
						}catch(Exception $e){
							$array[0]['status'] =  "Error ".$e.getMessage();
						}

							//Retreive data to view
						$result = $view->pendingInvoicesView();
						
						if ($result) {
							// output data of each row
							while($row = $result->fetch_assoc()) {
								//$output[]=$row;
						//$array[] =$row;
						
						
						?>
						<tbody>
							<tr class="clickable currentInvoice" data-toggle="collapse"  data-target="#group-of-rows-<?php echo $row['job_id']; ?>"  data-rowid="<?php echo $row['job_id']; ?>" data-invoice="<?php echo $row['job_code']; ?>" aria-expanded="false" aria-controls="group-of-rows-<?php echo $row['job_id']; ?>">
								<td style="width: 50px"><i class="fa fa-folder"></i></td>
								<td><?php echo $row['order_numb']; ?></td>
								<td><?php echo $row['mart_code']; ?></td>
								<td><?php echo $row['job_order_progress']; ?></td>
								<td><?php echo $row['job_pieces']; ?></td>
								<td>0x</td>
								<td>0x</td>
								<td>ready</td>
								<td>balance</td>
								<td>discount</td>
								<td><i class="fa fa-times"></i></td>
								<td><i class="fa fa-check"></i></td>
								<td><i class="fa fa-link" aria-hidden="true"></i></td>
							</tr>
						</tbody>
						<tbody class="mb-4" id="group-of-rows-<?php echo $row['job_id']; ?>" class="collapse">
							<!--<tr class="table-warning">
								<td><i class="fa fa-folder-open"></i> child row</td>
								<td>data 1</td>
								<td>data 1</td>
								<td>data 1</td>
							</tr>
							<tr class="table-warning">
								<td><i class="fa fa-folder-open"></i> child row</td>
								<td>data 1</td>
								<td>data 1</td>
								<td>data 1</td>
							</tr>-->
						</tbody>
						
						<?php
						
							}

						} else {
							//echo "0 results";
						}
						
						?>
						<!--
						<tbody>
							<tr class="clickable" data-toggle="collapse" data-target="#group-of-rows-1" aria-expanded="false" aria-controls="group-of-rows-1">
								<td><i class="fa fa-folder"></i></td>
								<td>data</td>
								<td>data</td>
								<td>data</td>
							</tr>
						</tbody>
						<tbody id="group-of-rows-1" class="collapse">
							<tr class="table-warning">
								<td><i class="fa fa-folder-open"></i> child row</td>
								<td>data 1</td>
								<td>data 1</td>
								<td>data 1</td>
							</tr>
							<tr class="table-warning">
								<td><i class="fa fa-folder-open"></i> child row</td>
								<td>data 1</td>
								<td>data 1</td>
								<td>data 1</td>
							</tr>
						</tbody>
						<tbody>
							<tr class="clickable" data-toggle="collapse" data-target="#group-of-rows-2" aria-expanded="false" aria-controls="group-of-rows-2">
								<td><i class="fa fa-folder"></i></td>
								<td>data</td>
								<td>data</td>
								<td>data</td>
							</tr>
						</tbody>
						<tbody id="group-of-rows-2" class="collapse">
							<tr class="table-warning">
								<td><i class="fa fa-folder-open"></i> child row</td>
								<td>data 2</td>
								<td>data 2</td>
								<td>data 2</td>
							</tr>
							<tr class="table-warning">
								<td><i class="fa fa-folder-open"></i> child row</td>
								<td>data 2</td>
								<td>data 2</td>
								<td>data 2</td>
							</tr>
						</tbody>-->
					</table>
			
			
			
				</div>
			</div>
		</div>
		

</div>
	
	
	
</div>




<script>
	/*		
 function getCustomerDetails(customerCode){
			//alert("Loading redirect "+customerCode );
			  $.ajax({
				url: 'backgroundServices/getCustomerDetails.php',
				type: 'post',
				dataType: 'json',
				data: {
					
					customerCode:customerCode
				},
				success: function(data) {
						  // alert("success "+  JSON.stringify(data.link_info));
						   //alert("success "+ JSON.stringify(data));
						   //success {"lead_info":[{"lead_id":"6","lead_code":"98522935790141480","lead_name":"","lead_company":"","lead_contact_code":"","lead_source":"","lead_status":"0","lead_type":"0","lead_created_at":"2019-12-28 19:55:50","lead_created_by":"lead_created_by","lead_timestamp":"2019-12-28 19:55:50"}]}
						   
						    var i;
						   var currentLeadData = "";
							for (i = 0; i < data.link_info.length; ++i) {
							//data.link_info[i].customer_code
							//$("#customerCode").hrml(data.link_info[i].customer_code);
							$("#customerName").html(data.link_info[i].customer_fname +", "+data.link_info[i].customer_lname);
							$("#customerPhone").html(data.link_info[i].customer_phone);
							$("#customerEmail").html(data.link_info[i].customer_email);
							//$("#customerStarch").val(data.link_info[i].customer_starch_level);
							//$("#customerPackaging").val(data.link_info[i].customer_packaging);
						  
								//currentLeadData += "<li class='list-group-item'  onclick=\"updateQueryStringParameter('localhost:8012/qsolutionsug/washupPOS/', 'page', 'viewClient' ,'customer','"+ data.link_info[i].customer_code +"')\" >"+ data.link_info[i].customer_fname +", "+ data.link_info[i].customer_lname +" </li>";

							}
							

				},
				error: function (data) {
					//console.log('An error occurred.');
					//console.log(data);
						 alert("fail "+ JSON.stringify(data));

				}
			});
		 }
		 */
		 
		 function getInvoiceBaskt(invoiceCode, rowId){
			 
					//alert("Loading redirect "+customerCode );
					  $.ajax({
						url: 'backgroundServices/getInvoiceBasket.php',
						type: 'post',
						dataType: 'json',
						data: {
							
							invoiceCode:invoiceCode
						},
						success: function(data) {
								  // alert("success "+  JSON.stringify(data.link_info));
								   
									var i;
								   var currentLeadData = "<tr class='table-primary'>"
																+"<td class='bg-dark' style='border:0'>&nbsp;</td>"
																+"<td> &nbsp;</td>"
																+"<td colspan='2'>Name</td>"
																+"<td>Service</td>"
																+"<td>Price</td>"
																+"<td>Upcharge</td>"
																+"<td><i class='fa fa-times'></i></td>"
																+"<td><i class='fa fa-check'></i></td>"
															+"</tr>";
									for (i = 0; i < data.link_info.length; ++i) {
									//data.link_info[i].customer_code
									//$("#customerCode").hrml(data.link_info[i].customer_code);
								
										currentLeadData += "<tr class='table-warning'>"
																+"<td class='bg-dark' style='border:0'>&nbsp;</td>"
																+"<td><i class='fa fa-folder-open text-primary'></i> &nbsp;</td>"
																+"<td colspan='2'>"+ data.link_info[i].laundary_name +"</td>"
																+"<td>"+ data.link_info[i].service_code +"</td>"
																+"<td  class='text-right'>"+ data.link_info[i].laundary_price +"</td>"
																+"<td class='text-right'>"+ data.link_info[i].basket_upcharge +"</td>"
																+"<td><i class='fa fa-times'></i></td>"
																+"<td><i class='fa fa-check'></i></td>"
															+"</tr>";

									}
									//alert(currentLeadData);
									$currentRowId = "#group-of-rows-"+rowId;
									$($currentRowId).html(currentLeadData);

						},
						error: function (data) {
							//console.log('An error occurred.');
							//console.log(data);
								 alert("fail "+ JSON.stringify(data));

						}
					});
		 }
		 
		 
		 $(".currentInvoice").click(function () {
		  //$("#container").append('<div class="module_holder"><div class="module_item"><img src="images/i-5.png" alt="Sweep Stakes"><br>sendSMS</div></div>');
			$invoice = $(this).data("invoice");
			rowId = $(this).data("rowid");
			//alert("text "+$invoice);
			getInvoiceBaskt($invoice, rowId);
		});
				 
		 //default redirect
			 /*	var params = new window.URLSearchParams(window.location.search);
				if(typeof(params.get('customer')) !== "undefined" && params.get('customer') !== null){
					 getCustomerDetails(params.get('customer'));
				}	*/		
		 	getCustomerDetails("");

</script>