<?php /* Template Name: Dev ERP Template */ 
ob_start();
	if( isset($_GET['act']) ) {
		if( $_GET['act'] == 'do_n' ) { 
		echo DevNoShipmentCsv(); 
		}
		if( $_GET['act'] == 'do_y' ) { 
		echo DevOnShipmentCsv(); 
		}
	}
	
	
	
	//session_start();
	//echo '<pre>';
		//print_r($_SESSION);
	//echo '</pre>';
?>

<?php get_header('erp'); ?>

<style type="text/css">
	
	.cs-csvb strong{margin-right:2%;}
	.cs-csvb { margin-top:3%; padding:0px; }
	.lost_password { display: none; }
	table tbody tr th:nth-child(2){width:25%;}
	#cs-mlink:hover {color: #337ab7 !important;
    text-decoration: underline;}
	.page-id-21 .wrap { max-width: 100%; padding-left: 5em; padding-right: 5em; }
	.cs-flt-form input[type=radio] { margin-top:0; }
	input[name=forder] { width: 30%; height: 35px; margin-left: 21px;display: inline; }
	.main-bg-table { padding: 0 10px; }
    #main table { overflow-x: scroll; display: inline-table; margin: 0 auto; }
	table tbody tr th:nth-child(2):hover a{color:#23527c;}
	table tbody tr td { padding:20px !important; }
	input[type=radio] { margin-right: 10px; }
	.cs-bottom button a, .cs-bottom button a:hover, .cs-bottom button a:focus { color:#fff;text-decoration:none; }
	.cs-bottom { margin-top: 20px; padding-left: 0; border-top: 1px solid #eee; padding-top: 20px;margin-bottom: 50px; }
	.cs-bottom strong { margin-right:10px; }
	.cs-red { color: red; }
	button[name=filter_rec], button.cs-cl { margin-right: 8px; margin-left: 8px; }
	.cs-flt-form select { width: 30%; height: 35px; margin-left: 10px; margin-right: 5px; }
	.cs-flt-form select[name=forder] { margin-left: 23px; }
	.cs-cl { padding-left: 21px; padding-right: 21px;margin-left: 2% !important; }
	.popup-overlay, .popup-overlay_sod { background-color: #000; height: 100%;
	left: 0; opacity: 0.7; position: fixed; top: 0; width: 100%; z-index: 2147483646; display: none; }
	.popup-main, .popup-main-edit, .popup-main_sod { background: #fff; bottom: 0; color: #000; height: 100%; left: 0; margin: auto; padding: 25px; position: fixed; right: 0; top: 0; width: 600px; z-index: 2147483647; display: none; margin-top:14px; margin-bottom: 10px; overflow: scroll;}
	.popup-main h1, .popup-main-edit h1, .popup-main_sod h1 { font-size: 1.45em; font-weight: 700; line-height: 1.2em; margin: 0 auto 1.2em; color: #000; padding-top:0px; }
	.popup-main p, .popup-main-edit p, .popup-main_sod p { color: #c0c0c0; font-size: 17px; }
	.popup-main .popup-close, .popup-main-edit .popup-close, .popup-main_sod .popup-close_sod { background: #fff; color: #2a2a2a; cursor: pointer; font-size: 18px; font-weight: 700; padding: 4px 12px 6px; position: absolute; right: 0; top: 0; }
	.cs-pltval label, .cs-corval label, .cs-whouseval label{width:100%;}
	.cs-pltval input[type=text], .cs-corval input[type=text], .cs-whouseval input[type=text]{width:65%;}
	.cs-drp {width:80%;float:left;}
	.cs-rm-val.fa-close{cursor: pointer;}
	.cs-cl{margin-left: 2% !important;}
	.cs_sod{cursor: pointer;}
	.cs_sod:hover{text-decoration:underline;}
	.popup-main_sod p{color:#000;}
	table tbody tr td .popup-main_sod {height:50%;margin-top:10%;}
	table tbody tr td a{text-decoration:underline;}
	.cs-cornred{background: #00b7ff33;}
	.cs-update{background: #0080004d;}
</style>

<section class="main-wrap">
	<div class="container about-heading">
	<h2 data-fontsize="28" data-lineheight="30"><a href="http://www.krugg.us/dev-erp/" id="cs-mlink">ERP</a><?php if(is_user_logged_in()){ ?>
	<span style="float:right;"><?php
	$redirect = 'http://www.krugg.us/dev-erp/';
	echo '<a class="cs-lg" href="'.wp_logout_url( $redirect ).'" />Logout</a>' ?> </span>
	<?php } ?>
	</h2>
		<?php if(isset($_GET['act']))
	{
		if($_GET['act'] == 'ddl')
		{
			?>
			<div class="col-sm-12">
				<div class="alert alert-success cs-listsuccess" style="display:none;">
					
				</div>
			</div>
			<div class="col-sm-4" id="platform-list">
				<h4>Platform</h4>
				<?php global $wpdb;
				$dprows = $wpdb->get_results( "SELECT `values` FROM wp_dev_erpdropdown WHERE `dropdown_name` = 'Platform'" );
				//pr($dprows); 
				$key = 'Platform';
				?>
				<ul id="cs-list-plt">
				<?php echo fun_plt($dprows,$key); ?>
				</ul>
				<form action="" method="POST" class="cs-pltval">
				<div class="form-group">
					<label>New Platform value</label>
					<input name="cs-plt" type="text" />
					<button type="submit" name="cs-plt-smt" value="Add" class="btn btn-primary cs-plt-sub"> Add</button>
					</div>
				</form>
			</div>
			<div class="col-sm-4" id="courier-list">
				<h4>Courier</h4>
				<?php global $wpdb;
				$dprows = $wpdb->get_results( "SELECT `values` FROM wp_dev_erpdropdown WHERE `dropdown_name` = 'Courier'" );
				?>
				<ul id="cs-list-courier">
				<?php echo fun_plt($dprows,'Courier'); ?>
				</ul>
				<form action="" method="POST" class="cs-corval">
				<div class="form-group">
					<label>New Courier value</label>
					<input name="cs-plt" type="text" />
					<button type="submit" name="cs-plt-smt" value="Add" class="btn btn-primary cs-courier-sub"> Add</button>
					</div>
				</form>
			</div>
			<div class="col-sm-4" id="whouse-list" >
				<h4>Warehouse</h4>
				<?php global $wpdb;
				$dprows = $wpdb->get_results( "SELECT `values` FROM wp_dev_erpdropdown WHERE `dropdown_name` = 'Warehouse'" );
				?>
				<ul id="cs-list-whouse">
				<?php echo fun_plt($dprows,'Warehouse'); ?>
				</ul>
				<form action="" method="POST" class="cs-whouseval">
				<div class="form-group">
					<label>New Warehouse value</label>
					<input name="cs-plt" type="text" />
					<button type="submit" name="cs-plt-smt" value="Add" class="btn btn-primary cs-whouse-sub"> Add</button>
					</div>
				</form>
			</div>
			<?php
		}
	} else {?>
	<!--<div><a href="http://localhost/wordpress/emp/">LOGO</a></div>-->
		<?php 
		if(!is_user_logged_in()){
		echo do_shortcode('[woocommerce_my_account]'); 
		} else {
		?>
		<div class="col-sm-6">
		<h4>FILTER BY...</h4>
		<?php //echo '<pre>';
		//print_r($_POST);
		?>
			<form action="" method="POST" class="cs-flt-form">
		
		<?php 
		//pr($_POST);
			$show = 'style="display:none;"';
			$o_v = $_POST['cs-filter'];
			$p_v = $_POST['cs-ptfilter'];
			$ck = $pk = $co = $uo = '';
			if($o_v == 'orderf'){
				$ck = 'checked';
			}
			elseif($o_v == 'openorders'){
				$uo = 'checked';	
				$show = 'style="display:block;"';
			}
			elseif($o_v == 'closeorders'){
				$co = 'checked';	
				$show = 'style="display:block;"';
			}
			if($p_v == 'platformf'){
				$pk = 'checked';
			}
			?>
			<div class="form-group">
			<input type="radio" name="cs-filter" value="orderf" <?php echo $ck; ?> id="cs-of"><label>Order#</label>
			<?php global $wpdb; 
					$order_rows = $wpdb->get_results( "SELECT `order_id` FROM `wp_deverp` WHERE `status` = '1' GROUP BY `order_id`" );
			$order_val = '';
			if($o_v == 'orderf')	{
				$order_val = $_POST['forder'];
			}
			?>
			<input type="text" name="forder" placeholder="Enter order ID" value="<?php echo $order_val; ?>" />
			<button type="submit" class="btn btn-primary" name="filter_rec">Filter Records</button>
			
			</div>
			<div class="form-group">
				<?php 
			$p_v = $_POST['cs-filter'];
			$ck = '';
			if($p_v == 'platformf'):
				$ck = 'checked';
			endif;
		?>
			<input type="radio" name="cs-filter" value="platformf" <?php echo $ck; ?> ><label>Platform</label>
			<?php global $wpdb; 
					$platform_rows = $wpdb->get_results( "SELECT `Platform` FROM `wp_deverp` WHERE `status` = '1' GROUP BY `Platform`" );
			?>
			<select name="fplatform" >
			<option value="">Select</option>
			<?php 
			
				foreach($platform_rows as $platform_row){
					
					$order_val = $_POST['fplatform'];
					//$fp = $_POST['cs-ptfilter'];
					
					$op = $platform_row->Platform;
					$opval = $platform_row->Platform;
					if($op == '')
					{
						$op = 'Null';
						$opval = 'Blank entry';
					}
					
					
					$sel = '';
					if($order_val != ''):
				if($order_val == $op): $sel = 'selected'; endif;
				endif;
					echo '<option value="'.$op.'" '.$sel.'>'.$opval.'</option>';
				}
			?>
			</select>
			<!--<input type="radio" name="cs-filter" value="openorders" <?php //echo $uo; ?> class="cs-cp" ><label>Open Orders</label>-->
			<button type="button" class="btn btn-primary cs-cl" >Clear Filter</button>
			
		</div>
		<!--<div class="form-group">		
			<input type="radio" name="cs-filter" value="closeorders" <?php //echo $co; ?> class="cs-cp"><label>Close Orders</label>
			
		</div>	-->
		
		<!--<div class="form-group" id="pl-filter" >
			<!--<input type="radio" name="cs-ptfilter" value="platformf" <?php //echo $pk; ?> >-->
			<!--<label>Platform</label>
			<?php /*global $wpdb; 
					$platform_rows = $wpdb->get_results( "SELECT `Platform` FROM `wp_deverp` WHERE `status` = '1' GROUP BY `Platform`" ); */
			?>
			<select name="fplatform" >
			<?php //print_r($_POST);?>
			<option value="">Select</option>
			<?php 
			
				/*foreach($platform_rows as $platform_row){
					
					$order_val = $_POST['fplatform'];
					//$fp = $_POST['cs-ptfilter'];
					
					$op = $platform_row->Platform;
					$opval = $platform_row->Platform;
					if($op == '')
					{
						$op = 'Null';
						$opval = 'Blank entry';
					}
					
					
					$sel = '';
					if($order_val != ''):
				if($order_val == $op): $sel = 'selected'; endif;
				endif;
					echo '<option value="'.$op.'" '.$sel.'>'.$opval.'</option>';
				} */
			?>
			</select>
		
		</div>-->
		</form>
	</div>

	<div class="col-sm-6" style="text-align:right;margin-top: 67px;">
	<a href="http://www.krugg.us/dev-erp-products/"><button type="button" class="btn btn-primary ">Product Portal</button></a>
	<button type="button" class="btn btn-primary cs-add your-anchore" data-toggle="show_popup">Add Record</button>
	<button type="button" class="btn btn-primary cs-del" data-id="">Delete Record</button>
	<button type="submit" class="btn btn-primary cs-edit" data-toggle="show_popup_edit" data-id="" name="edit">Edit Record</button>
	<div class="col-sm-12 cs-csvb">
	<strong>REPORT</strong>
			<a href="<?php echo site_url(); ?>/dev-shipment-detail/" target="_blank"><button type="button" class="btn btn-primary" >No confirmed shipment on ETA date</button></a>
			<a href="<?php echo site_url(); ?>/dev-timely-shipment/" target="_blank"><button type="button" class="btn btn-primary" >Check for timely shipment</button></a>
			</div>
	
	</div>
	
	<!-- msg -->
	<div class="col-sm-12">
	<div class="alert cs-formsuccess" style="display:none;">
			
		</div>
	<div class="alert alert-success cs-formdel" style="display:none;">
			<strong>Success!</strong> Record successfully deleted
		</div>
	
	
		<div class="alert alert-success cs-formedt" style="display:none;">
			<strong>Success!</strong> record successfully edited.
		</div>
	
	</div>
	<!-- msg -->
	
		<main id="main" class="site-main" role="main">
			<div class="main-bg-table">
			<table class="table">
			  <thead>
				<tr>
				  <th scope="col"></th>	
				  <th scope="col">Order#</th>
				  <th scope="col">Platform</th>
				  <th scope="col">Date Entered</th>
				  <th scope="col">Address</th>
				  <!--<th scope="col">Zip code</th>-->
				  <th scope="col">Shipping Method</th>
				  <th scope="col">Order Status</th>
				  <th scope="col">Reason For </br>Order</th>
				</tr>
			  </thead>
			  <tbody>
			  <?php 
			   global $wpdb;
			  if(!empty($_POST['cs-filter']))
			  {
				  $csf = $_POST['cs-filter'];
				if($_POST['cs-filter'] == 'orderf')
				{
					$of = $_POST['forder'];
					$myrows = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE `status` = '1' AND `order_id`='$of' ORDER BY `id` DESC" );
				}
				
				/*elseif($_POST['cs-filter'] == 'openorders' AND $_POST['fplatform'] == ''){
					
					$myrows = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE `status` = '1' AND `Date_Delivered` = '' ORDER BY `id` DESC" );
				}
				elseif($_POST['cs-filter'] == 'closeorders' AND $_POST['fplatform'] == ''){
					
					$myrows = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE `status` = '1' AND `Date_Delivered` != '' ORDER BY `id` DESC" );	
					
				}
				elseif($_POST['fplatform'] != '' AND $_POST['cs-filter'] == 'openorders'){
					
					$op = $_POST['fplatform'];
					if($op == 'Null'){
						$op = '';
					}
					$myrows = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE `status` = '1' AND `Date_Delivered` = '' AND `Platform`='$op' ORDER BY `id` DESC");
				}*/
				elseif($_POST['fplatform'] != ''){
					
					$op = $_POST['fplatform'];
					if($op == 'Null'){
						$op = '';
					}
					$myrows = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE `status` = '1' AND `Platform`='$op' ORDER BY `id` DESC");
				}					
			  }
			  else{
				$myrows = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE `status` = '1' ORDER BY `id` DESC" );
			  }
			 
			   
			  if(isset($_GET['id']))
			  {
				  echo all_devrec($myrows,$_GET['id']);
			  }
			  else{
				  echo all_devrec($myrows);
			  }
			  ?>				
				
				
			  </tbody>
			</table>
			</div>
			<div class="col-sm-12 cs-bottom" st>
			<!--<strong>REPORT</strong>
			<a href="<?php echo site_url(); ?>/shipment-detail/" target="_blank"><button type="button" class="btn btn-primary" >No confirmed shipment on ETA date</button></a>
			<a href="<?php echo site_url(); ?>/timely-shipment/" target="_blank"><button type="button" class="btn btn-primary" >Check for timely shipment</button></a>-->
			<a href="<?php echo site_url(); ?>/dev-erp?act=ddl"><button type="button" class="btn btn-primary" style="float:right;">DDL form</button></a>
			</div>
		</main>
	<?php } }?>
	</div>
</section>	

<?php get_footer('erp'); ?>

<div class="popup-overlay"></div>
<div class="popup-main">
	<span class="popup-close">X</span>
	<h1>Add New Record</h1>
	<p>
		<form action="" method="POST" class="cs-form" id="cs-addform">
			<div class="form-group">
				<label for="order">Order#</label>
				<input type="text" class="form-control" id="order" name="order">
			</div>
			<div class="form-group">
				<label for="platform">Platform</label>
				<select class="form-control" id="platform"  name="platform">
					<option value="">Select</option>
					<option value="Amazon">Amazon</option>
					<option value="Artizan Lighted Mirrors">Artizan Lighted Mirrors</option>
					<option value="Houzz">Houzz</option>
					<option value="Jet">Jet</option>
					<option value="Wholesale">Wholesale</option>
					<option value="Wayfair">Wayfair</option>
				</select>
			</div>
			<div class="form-group">
				<label for="Date_Entered">Date Entered</label>
				<input type="date" class="form-control" id="Date_Entered" name="Date_Entered" onkeydown="return false">
			</div>
			<div class="form-group">
				<label for="Customer_Name">Customer Name</label>
				<input type="text" class="form-control" id="Customer_Name" name="Customer_Name">
			</div>
			
			
			<div class="form-group">
				<label for="Address">Address</label>
				<input type="text" class="form-control" id="Address" name="Address">
			</div>
			
			<div class="form-group">
				<label for="Address1">Address1</label>
				<input type="text" class="form-control" id="Address1" name="Address1">
			</div>
			
			<div class="form-group">
				<label for="Address">Address2</label>
				<input type="text" class="form-control" id="Address2" name="Address2">
			</div>
			
			<div class="form-group">
				<label for="City">City</label>
				<input type="text" class="form-control" id="City" name="City">
			</div>
			
			<div class="form-group">
				<label for="State">State</label>
				<input type="text" class="form-control" id="State" name="State">
			</div>
			
			<div class="form-group">
				<label for="Zip">Zip</label>
				<input type="text" class="form-control" id="Zip" name="Zip">
			</div>
			
			<div class="form-group">
				<label for="Phone">Phone</label>
				<input type="text" class="form-control" id="Phone" name="Phone">
			</div>
			
			
			<div class="form-group">
				<label for="Shipping_Method">Shipping Method</label>
				<input type="text" class="form-control" id="Shipping_Method" name="Shipping_Method">
			</div>
			<div class="form-group">
				<label for="Order_Status">Order Status</label>
				<input type="text" class="form-control" id="Order_Status" name="Order_Status">
			</div>
			
			<div class="form-group">
				<label for="Reason">Reason for Order</label>
				<textarea class="form-control" name="Reason"></textarea>
			</div>
			
			<button type="submit" class="btn btn-default" name="submit" value="submit">Submit</button>
			<button type="reset" class="btn btn-default" name="submit" value="submit">Reset</button>
		</form>
	</p>
</div>

<?php
	if( isset($_GET['id']) ) {
		$id = $_GET['id'];
		global $wpdb;
		$update_row = $wpdb->get_results( "SELECT * FROM wp_deverp WHERE id='$id'" );
	}
?>

<div class="popup-main-edit">
	<span class="popup-close">X</span>
	<h1>Edit record</h1>
	<p>
		<form action="" method="POST" class="cs-form" id="cs-updateform">
			<div class="form-group">
				<label for="order">Order#</label>
				<input type="hidden" value="<?php echo $id; ?>" name="id"/>
				<input type="text" class="form-control" id="order" name="order" value="<?php echo $update_row[0]->order_id; ?>">
			</div>
			<div class="form-group">
				<label for="platform">Platform</label>
				<?php $pval = $update_row[0]->Platform; ?>
				<select class="form-control" id="platform"  name="platform">
					<option value="">Select</option>
					<option value="Amazon" <?php if($pval == 'Amazon' ): echo 'selected'; endif; ?> >Amazon</option>
					<option value="Artizan Lighted Mirrors" <?php if($pval == 'Artizan Lighted Mirrors' ): echo 'selected'; endif; ?>>Artizan Lighted Mirrors</option>
					<option value="Houzz" <?php if($pval == 'Houzz' ): echo 'selected'; endif; ?> >Houzz</option>
					<option value="Jet" <?php if($pval == 'Jet' ): echo 'selected'; endif; ?>>Jet</option>
					<option value="Wholesale" <?php if($pval == 'Wholesale' ): echo 'selected'; endif; ?>>Wholesale</option>
					<option value="Wayfair" <?php if($pval == 'Wayfair' ): echo 'selected'; endif; ?>>Wayfair</option>
				</select>
			</div>
			<div class="form-group">
				<label for="Date_Entered">Date Entered</label>
				<input type="date" class="form-control" id="Date_Entered" name="Date_Entered" value="<?php echo $update_row[0]->Date_Entered;?>" onkeydown="return false" >
			</div>
			<!--<div class="form-group">
				<label for="ETA_Shipment">ETA Shipment</label>
				<input type="date" class="form-control" id="ETA_Shipment" name="ETA_Shipment" value="<?php //echo $update_row[0]->ETA_Shipment;?>">
			</div>-->
			
			<div class="form-group">
				<label for="Customer_Name">Customer Name</label>
				<input type="text" class="form-control" id="Customer_Name" name="Customer_Name" value="<?php echo $update_row[0]->Customer_Name; ?>" />
			</div>
			
			
			<div class="form-group">
				<label for="Address">Address</label>
				<input type="text" class="form-control" id="Address" name="Address" value="<?php echo $update_row[0]->Address; ?>" />
			</div>
			
			<div class="form-group">
				<label for="Address1">Address1</label>
				<input type="text" class="form-control" id="Address1" name="Address1" value="<?php echo $update_row[0]->Address1; ?>" />
			</div>
			
			<div class="form-group">
				<label for="Address">Address2</label>
				<input type="text" class="form-control" id="Address2" name="Address2" value="<?php echo $update_row[0]->Address2; ?>" />
			</div>
			
			<div class="form-group">
				<label for="City">City</label>
				<input type="text" class="form-control" id="City" name="City" value="<?php echo $update_row[0]->City; ?>" >
			</div>
			
			<div class="form-group">
				<label for="State">State</label>
				<input type="text" class="form-control" id="State" name="State"  value="<?php echo $update_row[0]->State; ?>" />
			</div>
			
			<div class="form-group">
				<label for="Zip">Zip</label>
				<input type="text" class="form-control" id="Zip" name="Zip" value="<?php echo $update_row[0]->Zip; ?>" >
			</div>
			
			<div class="form-group">
				<label for="Phone">Phone</label>
				<input type="text" class="form-control" id="Phone" name="Phone" value="<?php echo $update_row[0]->Phone; ?>" >
			</div>
			
			
			<div class="form-group">
				<label for="Shipping_Method">Shipping Method</label>
				<input type="text" class="form-control" id="Shipping_Method" name="Shipping_Method" value="<?php echo $update_row[0]->Shipping_method; ?>" />
			</div>
			<div class="form-group">
				<label for="Order_Status">Order Status</label>
				<input type="text" class="form-control" id="Order_Status" name="Order_Status" value="<?php echo $update_row[0]->order_status; ?>"   />
			</div>
			
			
			
			<div class="form-group">
				<label for="Reason">Reason for Order</label>
				<textarea class="form-control" name="Reason"><?php echo $update_row[0]->Reason;?></textarea>
			</div>
			<input type="hidden" value="<?php echo $_GET['id'];?>" name="id" />
			<!--<div class="form-group">
				<?php //$sval = $update_row[0]->Shipped_Confirmed;?>
				<label for="Shipped_Confirmed">Shipped Confirmed</label>
				<select class="form-control" id="Shipped_Confirmed"  name="Shipped_Confirmed" >
					<option value="">Select</option>
					<option value="Yes" <?php //if($sval == 'Yes' ): echo 'selected'; endif; ?>>Yes</option>
					<option value="No" <?php //if($savl == 'No'): echo 'selected'; endif; ?>>No</option>
				</select>
			</div> 
			<div class="form-group">
				<label for="Tracking_Number">Tracking Number</label>
				<input type="text" class="form-control" id="Tracking_Number" name="Tracking_Number" value="<?php //echo $update_row[0]->Tracking_Number;?>">
			</div>
			<div class="form-group">
				<label for="Courier">Courier</label>
				<?php //$uval = $update_row[0]->Courier; ?>
				<select class="form-control" id="Courier"  name="Courier">
					<option value="">Select</option>
					<option value="FedEx" <?php //if($uval == 'FedEx'): echo 'selected'; endif; ?>>FedEx</option>
					<option value="Freight" <?php //if($uval == 'Freight'): echo 'selected'; endif; ?>>Freight</option>
					<option value="UPS" <?php //if($uval == 'UPS'): echo 'selected'; endif; ?> >UPS</option>
					<option value="UPS" <?php //if($uval == 'UPS'): echo 'selected'; endif; ?> >USPS</option>
				</select>
			</div>
			<div class="form-group">
				<label for="Date_Delivered">Date Delivered</label>
				<input type="date" class="form-control" id="Date_Delivered" name="Date_Delivered" value="<?php //echo $update_row[0]->Date_Delivered;?>" >
			</div>
			<div class="form-group">
				<label for="Delivered_Location">Delivered Location</label>
				<input type="text" class="form-control" id="Delivered_Location" name="Delivered_Location" value="<?php //echo $update_row[0]->Delivery_Location;?>" >
			</div>
			<div class="form-group">
				<label for="Warehouse">Warehouse</label>
				<?php //$wval = $update_row[0]->Delivery_Location;?>
				<select class="form-control" id="Warehouse"  name="Warehouse">
					<option value="">Select</option>
					<option value="AJF" <?php //if($wval == 'AJF'): echo 'selected'; endif;?> >AJF</option>
					<option value="Amazon" <?php //if($wval == 'Amazon'): echo 'selected'; endif;?> >Amazon</option>
					<option value="Storage" <?php //if($wval == 'Storage'): echo 'selected'; endif;?> >Storage</option>
				</select>
			</div>
			<div class="form-group">
				<label for="ETA_Delivered">ETA Delivered</label>
				<input type="date" class="form-control" id="ETA_Delivered" name="ETA_Delivered" value="<?php //echo $update_row[0]->ETA_Delivery; ?>" >
			</div>-->
			
			<button type="submit" class="btn btn-default cs-update" name="Update" value="Update" data-id="">Update</button>
		</form>
	</p>
</div>

<script type="text/javascript">
	var url_site = 'http://bearonunicycle.us/dev-erp/';
	
	//jQuery('.cs_sod').click(function(){
	jQuery(document).on('click','.cs_sod',function(){
		
		//console.log('dd');
		console.log(jQuery(this).parent());
		jQuery('table tbody tr').removeClass('cc-active');
		jQuery(this).parent().addClass('cc-active');
		window.setTimeout( show_popup_OrderDetail, 50 );
		
		//console.log(jQuery(this).find('.popup-overlay_sod'));
		//jQuery('cc-active').find('.popup-overlay_sod').show();
        //jQuery('cc-active').find('.popup-main_sod').slideDown(200);
		
	});
	
	function show_popup_OrderDetail() {
                jQuery('.cc-active .popup-overlay_sod').show();
                jQuery('.cc-active .popup-main_sod').slideDown(200);
            };
	
	//jQuery('.popup-close_sod , .popup-overlay_sod').on('click', function() {
	jQuery(document).on('click','.popup-close_sod , .popup-overlay_sod', function() {
                jQuery('.popup-overlay_sod, .popup-main_sod'  ).hide(0);
            });
	
		jQuery('.cs-cl').click(function(){	
			window.location.href = url_site;
		});
		jQuery(document).ready(function() {
			
			var v = jQuery('table tbody tr.cs-row-active').data('id');
			jQuery('.cs-del').attr('data-id',v);
			
					
			jQuery('.cs-edit').click(function(event){
				event.preventDefault();
				var val = jQuery('table tbody tr.cs-row-active').data('id');
			
			window.location.href=''+url_site+'?id='+val+''
			});
			jQuery(document).on('change','table tbody tr th input[type=radio]', function(){
		//jQuery('table tbody tr th input[type=radio]').change(function(){
			console.log('test11');
				jQuery('table tbody tr').removeClass('cs-row-active');
				jQuery(this).closest('tr').addClass('cs-row-active');
			});

		jQuery('.popup-close').on('click', function() {
                jQuery('.popup-overlay, .popup-main, .popup-main-edit'  ).hide(0);
            });

            function show_popup() {
                jQuery('.popup-overlay').show();
                jQuery('.popup-main').slideDown(200);
            };
			
			function show_popup_edit() {
                jQuery('.popup-overlay').show();
                jQuery('.popup-main-edit').slideDown(200);
            };
			
            //window.setTimeout( show_popup, 1000 );

            jQuery('.cs-add[data-toggle="show_popup"]').on('click', function(nolink) {
            	nolink.preventDefault();
            	window.setTimeout( show_popup, 50 );
            });
			
			/* jQuery('.cs-edit[data-toggle="show_popup_edit"]').on('click', function(nolink) {
            	nolink.preventDefault();
            	window.setTimeout( show_popup_edit, 50 );
            }); */
			var url = window.location.href;
			//var result = url.split('id=');
			//alert( result[1] );		
			
			if (url.indexOf('?id') != -1) {
				
				window.setTimeout( show_popup_edit, 50 );
			}
			
			jQuery('.cs-del').click(function(){
				var id = jQuery('table tbody tr.cs-row-active').attr('data-id');
				var order_id = jQuery('table tbody tr.cs-row-active th:nth-child(2)').text();
				var txt;
				var r = confirm("Delete Order# "+order_id+" record?");
				if (r == true) {
					jQuery.ajax({
					type: "post",
					url: "<?php echo admin_url('admin-ajax.php'); ?>",   
            data: "action=row_devdel&id="+id,  
            success: function(response){
				 jQuery('.alert').hide();
				 jQuery('.cs-formdel').show();
				 jQuery('table tbody').html(response);
            }
        });
				} else {
					txt = "You pressed Cancel!";
				}
			});
			
			jQuery('#cs-addform').submit(function(event) {
				event.preventDefault();
				var values = jQuery(this).serialize();
				jQuery.ajax({
					type: "post",
					dataType: "json",
					url: "<?php echo admin_url('admin-ajax.php'); ?>",   
            data: "action=row_devadd&"+values,  
            success: function(resp){
				//alert(resp);
				var cl = '';
				 
				 if(resp.resp == 'success')
				 {
					var cl = 'alert-success'; 
				 }
				 else if(resp.resp == 'error'){
					var cl = 'alert-danger'; 
				 }
				 jQuery('.cs-formsuccess').addClass(cl).html(resp.message).show();
				 //alert('sfsdfs');
				 console.log(resp.val);
				 if(resp.resp == 'success'){
					 //alert('insuccess');
					 
					 
					jQuery('table tbody').html(resp.val);
				 }
				 //console.log('test1');
				 jQuery('#cs-addform')[0].reset();
				 //console.log('test2');
				  jQuery('.popup-overlay, .popup-main, .popup-main-edit').hide(0);
				  //console.log('test3');
            }
        });
				
			});
			
			jQuery('#cs-updateform').submit(function(event) {
				event.preventDefault();
				var values = jQuery(this).serialize();
				jQuery.ajax({
					type: "post",
					url: "<?php echo admin_url('admin-ajax.php'); ?>",   
            data: "action=row_devedt&"+values,  
            success: function(response){
			     //alert(response);
				 jQuery('.alert').hide();
				 jQuery('.cs-formedt').show();
				 jQuery('table tbody').html(response);
				  jQuery('.popup-overlay, .popup-main, .popup-main-edit'  ).hide(0);
				  window.history.pushState(null, null, url_site);
            }
        });
				
			});
			
			
			jQuery(document).on('click','.cs-rm-val',function(){
				//console.log('trst2');
				var rm_val = jQuery(this).data('id');
				var rm_key = jQuery(this).attr('data-key');
				//console.log('trst3');
				removeval(rm_val,rm_key);
			});
			
			function removeval(rm_val,rm_key){
				//console.log('trst4');
				var r = confirm("Are you sure, you want to delete "+rm_val+"?");
				if (r == true) {
				jQuery.ajax({
					type: "post",
					url: "<?php echo admin_url('admin-ajax.php'); ?>",   
					data: "action=Devdel_val&value="+rm_val+"&key="+rm_key,  
					success: function(response){
					//alert(response);
					
					//jQuery('.cs-formedt').show();
					 jQuery('.cs-listsuccess').html('<strong>Success!</strong> '+rm_val+' successfully deleted!');
					if(rm_key == 'Platform'){
						jQuery('#cs-list-plt').html(response);	
					}
					else if(rm_key == 'Courier' ){
						jQuery('#cs-list-courier').html(response);
					}
					else if(rm_key == 'Warehouse'){
						jQuery('#cs-list-whouse').html(response);
					}
					jQuery('.cs-listsuccess').show();
					}
					});
				} else{
					
				}
			}
			
			jQuery('.cs-plt-sub').click(function(event){
				event.preventDefault();
				var v = jQuery('.cs-pltval input[name=cs-plt]').val();
				var key = 'Platform';
				var formclass = 'cs-pltval';
				var listId = 'cs-list-plt';
				ajaxfun(v,key,formclass,listId);	
			});	
			
			jQuery('.cs-courier-sub').click(function(event){
				event.preventDefault();
				var v = jQuery('.cs-corval input[name=cs-plt]').val();
				var key = 'Courier';
				var formclass = 'cs-corval';
				var listId = 'cs-list-courier';
				ajaxfun(v,key,formclass,listId);	
			});

			jQuery('.cs-whouse-sub').click(function(event){
				event.preventDefault();
				var v = jQuery('.cs-whouseval input[name=cs-plt]').val();
				var key = 'Warehouse';
				var formclass = 'cs-whouseval';
				var listId = 'cs-list-whouse';
				ajaxfun(v,key,formclass,listId);	
			});
			
			
			
			function ajaxfun(v,key,formclass,listId){
				jQuery.ajax({
					type: "post",
					url: "<?php echo admin_url('admin-ajax.php'); ?>",   
        data: "action=Devinsert_platform&key="+key+"&value="+v,  
            success: function(response){
				  jQuery('.cs-listsuccess').html('<strong>Success!</strong> New '+key+' value successfully added');
				   jQuery('.'+formclass+'')[0].reset();
				 jQuery('.cs-listsuccess').show();
				 jQuery('#'+listId+'').html(response);
					}
				});	
			}
			
			
			jQuery('.cs-cp').click(function(){
				if(jQuery(this).is(":checked")){
					jQuery('#pl-filter').show();
				}
				else{
					jQuery('#pl-filter').hide();
				}
			});
			
			
			
			jQuery('#cs-of').click(function(){
				jQuery('#pl-filter').hide();
			});
			
        });
</script>