<commit_before><?php 
/*
Plugin Name: Store5 Order Grinder
Plugin URI: http://store5.ca
Description: Takes entries from a Gravity Form and combines them with order details exported from Merchant POS and creates WooCommerce orders from the result.
Author: <NAME>
Version: 1.0
Author URI: http://allankenneth.com
Requires at least: 4.0.1
Tested up to: 4.3
Stable tag: 4.3
License: GPLv3 or later License
URI: http://www.gnu.org/licenses/gpl-3.0.html
WC requires at least: 2.2
WC tested up to: 2.3
Woohoo!
*/
//add_filter('show_admin_bar', '__return_false');
add_action( 'admin_menu', 'store5_menu' );
function store5_menu() {
	add_submenu_page(
		'woocommerce',
		__( 'Order Grinder', 's5-order-grinder' ),
		__( 'Order Grinder', 's5-order-grinder' ),
		'manage_woocommerce',
		'store5',
		'store5_options'
	);
}
function store5_options() {
	//if ( !current_user_can( 'manage_options' ) )  {
	//	wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
	//}
	?>
	<h1>Order Grinder</h1>
	<p>Combine Merchant POS Transaction Journals with <a href="http://woothemes.com/woocommerce">Woocommerce</a>.</p>
	<div style="float: left; margin: 1%; padding: 1%; width: 70%;">	
	<?php $form_id = '1'; ?>
	<?php $search_criteria['field_filters'][] = array( 'key' => '13', 'value' => 'Unprocessed' ); ?>
	<?php $entry = GFAPI::get_entries( $form_id, $search_criteria ); ?>
	<?php $flip = array_reverse($entry) ?>
	<?php 
	$howmany = count($flip);
	$last = $howmany - 1;
	$firstdate = explode(' ', $flip[0]['date_created']);
	$lastdate = explode(' ', $flip[$last]['date_created']);

	?>
	<?php foreach($flip as $order) : ?>
		<h1><?php echo $order['id'] ?>. <?php echo $order['14'] ?>  <?php echo $order['15'] ?></h1>
		<form action="/wp-content/plugins/store5/create.php" 
			class="addorder" 
			method="post" 
			style="<?php if($order['16.1']) echo 'border: 1px dashed red;' ?> background: #FFF; margin-bottom:30px; padding: 20px;">
		<input type="hidden" name="action" id="action" value="s5_new_order">
		<input type="hidden" name="gf_entry_id" id="gf_entry_id" value="<?php echo $order['id'] ?>">
		<?php $daydate = explode(' ', $order['date_created']) ?>
		<h2>Date added: <?php echo $daydate[0] ?></h2>
		Transaction ID: <input size="8" type="text" name="transid" id="transid" value="<?php echo $order["5"] ?>"><br>
		



		<?php if($order['17']): ?>
		<p>Order being held until <?php echo $order['17'] ?>. <a href="#oid<?php echo $order['id'] ?>" class="showorder">Show Order</a></p>
		<div class="hodor" id="oid<?php echo $order['id'] ?>">
		<?php endif ?>
		

		<div style="float: left; margin: 1%; padding: 1%; width: 46%;">

		<?php 
		// We support having multiple transaction IDs because it frequently happens that people will come back later
		// and add to their order. Here we detect if there are multiple transaction IDs and if there are
		// then we run the handy little mergeOrders($mutli) function and combine the items from each order
		$multitrans = explode(',', $order['5']);
		if(count($multitrans) > 1) { 
			$multi = Array();
			$combine = 1;
			foreach($multitrans as $trans) {
				array_push($multi, store5_getOrderDetails($trans));
			}
			$orderdeets = mergeOrders($multi);
		} else {
			$orderdeets = store5_getOrderDetails($order['5']);
			$combine = 0;
		}

		?>
		<?php if(count($orderdeets[0]['orderitems']) > 0): ?>
		<?php foreach($orderdeets as $detail): ?>
			Colleague: <input type="text" name="colleague" id="colleague" value="<?php echo $detail['colleague'] ?>"><br>
			Ship Fee: $<input type="text" name="shipcharged" id="shipcharged" value="<?php echo $detail['shipcharged'] ?>">
			<h3><?php if($combine) echo 'Combined ' ?>Order Items</h3>
			<ul>
			<?php foreach($detail['orderitems'] as $item) : ?>
			<li>
				<input type="hidden" 
					id="item-<?php echo $item['sku'] ?>"
					name="deets[]" 
					value="<?php echo $item['qty'] . '||' . $item['sku'] ?>">
				<a href="#" class="btn btn-sm removeitem">x</a>
				<a href="#" class="btn btn-sm markpacked">packed</a>
				<span>
				<span class="qty"><?php echo $item['qty'] ?></span> 
					x
				<?php echo $item['sku'] ?>
					-
				<?php echo $item['desc'] ?>
				</span>
			</li>
			<?php endforeach; ?>
			</ul>
			<hr>
		<?php endforeach;?>
		<?php else: ?>
			<hr>
			<p><strong>Could not find this transaction in the current journal. 
				Please upload a new journal within the correct time period.</strong></p>
			<hr>
		<?php endif; ?>
		<?php if($order['18.1']): ?>
		<h3 style="text-transform: uppercase">Remove Prices</h3>
		<hr>
		<?php endif; ?>
		<?php if($order['17']): ?>
		<strong>Hold until: <?php echo $order['17'] ?></strong>
		<hr>
		<?php endif; ?>
		Shipment Method: <strong><?php echo $order['9'] ?></strong>
		<hr>
		Notes: <br>
		<textarea name="notes" cols="30" rows="5"><?php echo $order["4"] ?></textarea>
		<br>

		</div>
		<div style="float: left; margin: 1%; padding: 1%; width: 46%;">
		<h3>Address</h3>
		First Name: <input type="text" name="first_name" value="<?php echo $order["14"] ?>"><br>
		Last Name: <input type="text" name="last_name" value="<?php echo $order["15"] ?>"><br>
		Company: <input type="text" name="company" value="<?php echo $order["12"] ?>"><br>
		Address 1: <input type="text" name="address_1" value="<?php echo $order["2.1"] ?>"><br>
		Address 2: <input type="text" name="address_2" value="<?php echo $order["2.2"] ?>"><br>
		City: <input type="text" name="city" value="<?php echo $order["2.3"] ?>"><br>
		State: <input size="8" type="text" name="state" value="<?php echo $order["2.4"] ?>"><br>
		Code: <input type="text" name="code" value="<?php echo $order["2.5"] ?>"><br>
		<?php 
		// WTF GravityForms? Can't use a country code? 
		if($order['2.6'] == 'United States') {
			$cunt = 'US';
		} elseif($order['2.6'] == 'Canada') {
			$cunt = 'CA';
		} else {
			$cunt = $order['2.6'];
		} 
		?>
		Country: <input type="text" name="country" value="<?php echo $cunt ?>"><br>
		Phone: <input type="text" name="phone" value="<?php echo $order["7"] ?>"><br>
		Email: <input type="text" name="email" value="<?php echo $order["3"] ?>"><br>
		</div>
		<div style="clear:both"></div>
		<button class="btn btn-success">Process Order</button>
		<?php if($order['17']): ?>
		</div>
		<div style="clear:both"></div>
		<?php endif ?>

	</form>
	<?php endforeach; ?>
	</div>
	<div style="float: left; margin: 1%; padding: 1%; width: 20%;">
	<h1><?php echo $howmany ?> Orders</h1>
	<p>You will need a "Transaction Journal.csv" spanning the dates: <?php echo $firstdate[0] . ' - ' . $lastdate[0] ?>.</p>
	<form action="/wp-content/plugins/store5-order-grinder/upload.php" method="post" enctype="multipart/form-data" class="up"> 
		<div class="form-group">
			<input type="file" name="myFile" id="myFile"> 
			<button type="submit" class="btn btn-lg btn-warning btn-block" value="Upload">
			Upload Transaction Journal
			</button>
		</div>
	</form>
	<!--	<h3>Instructions</h3>
		<p>In Merchant Back Office, run a <strong>Transaction Journal</strong> report with the following parameters:</p>
		<ul>
			<li>Date Posted should be between the newest and oldest orders</li>
			<li>Journal # &amp; Transaction # fields should both be 1 - 99999999</li>
			<li>Print Summary, Print Drawer Count &amp;Print Detail should all be checked</li>
		</ul>
		<p>When the report comes up, click the export button (very far upper-left). Change the file type to CSV and save it to your desktop.</p>
		<p>Once that's done, come back here, click "Choose File;" locate and "Open" the newly exported "Transaction Journal.csv;" Then click the 'Upload &hellip;' button. </p>-->

	</div>

<style>
.hodor { display: none; }<commit_msg>add button class/styles for the 'packed' and 'x' buttons.<commit_after><?php 
/*
Plugin Name: Store5 Order Grinder
Plugin URI: http://store5.ca
Description: Takes entries from a Gravity Form and combines them with order details exported from Merchant POS and creates WooCommerce orders from the result.
Author: <NAME>
Version: 1.0
Author URI: http://allankenneth.com
Requires at least: 4.0.1
Tested up to: 4.3
Stable tag: 4.3
License: GPLv3 or later License
URI: http://www.gnu.org/licenses/gpl-3.0.html
WC requires at least: 2.2
WC tested up to: 2.3
Woohoo!
*/
//add_filter('show_admin_bar', '__return_false');
add_action( 'admin_menu', 'store5_menu' );
function store5_menu() {
	add_submenu_page(
		'woocommerce',
		__( 'Order Grinder', 's5-order-grinder' ),
		__( 'Order Grinder', 's5-order-grinder' ),
		'manage_woocommerce',
		'store5',
		'store5_options'
	);
}
function store5_options() {
	//if ( !current_user_can( 'manage_options' ) )  {
	//	wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
	//}
	?>
	<h1>Order Grinder</h1>
	<p>Combine Merchant POS Transaction Journals with <a href="http://woothemes.com/woocommerce">Woocommerce</a>.</p>
	<div style="float: left; margin: 1%; padding: 1%; width: 70%;">	
	<?php $form_id = '1'; ?>
	<?php $search_criteria['field_filters'][] = array( 'key' => '13', 'value' => 'Unprocessed' ); ?>
	<?php $entry = GFAPI::get_entries( $form_id, $search_criteria ); ?>
	<?php $flip = array_reverse($entry) ?>
	<?php 
	$howmany = count($flip);
	$last = $howmany - 1;
	$firstdate = explode(' ', $flip[0]['date_created']);
	$lastdate = explode(' ', $flip[$last]['date_created']);

	?>
	<?php foreach($flip as $order) : ?>
		<h1><?php echo $order['id'] ?>. <?php echo $order['14'] ?>  <?php echo $order['15'] ?></h1>
		<form action="/wp-content/plugins/store5/create.php" 
			class="addorder" 
			method="post" 
			style="<?php if($order['16.1']) echo 'border: 1px dashed red;' ?> background: #FFF; margin-bottom:30px; padding: 20px;">
		<input type="hidden" name="action" id="action" value="s5_new_order">
		<input type="hidden" name="gf_entry_id" id="gf_entry_id" value="<?php echo $order['id'] ?>">
		<?php $daydate = explode(' ', $order['date_created']) ?>
		<h2>Date added: <?php echo $daydate[0] ?></h2>
		Transaction ID: <input size="8" type="text" name="transid" id="transid" value="<?php echo $order["5"] ?>"><br>
		



		<?php if($order['17']): ?>
		<p>Order being held until <?php echo $order['17'] ?>. <a href="#oid<?php echo $order['id'] ?>" class="showorder">Show Order</a></p>
		<div class="hodor" id="oid<?php echo $order['id'] ?>">
		<?php endif ?>
		

		<div style="float: left; margin: 1%; padding: 1%; width: 46%;">

		<?php 
		// We support having multiple transaction IDs because it frequently happens that people will come back later
		// and add to their order. Here we detect if there are multiple transaction IDs and if there are
		// then we run the handy little mergeOrders($mutli) function and combine the items from each order
		$multitrans = explode(',', $order['5']);
		if(count($multitrans) > 1) { 
			$multi = Array();
			$combine = 1;
			foreach($multitrans as $trans) {
				array_push($multi, store5_getOrderDetails($trans));
			}
			$orderdeets = mergeOrders($multi);
		} else {
			$orderdeets = store5_getOrderDetails($order['5']);
			$combine = 0;
		}

		?>
		<?php if(count($orderdeets[0]['orderitems']) > 0): ?>
		<?php foreach($orderdeets as $detail): ?>
			Colleague: <input type="text" name="colleague" id="colleague" value="<?php echo $detail['colleague'] ?>"><br>
			Ship Fee: $<input type="text" name="shipcharged" id="shipcharged" value="<?php echo $detail['shipcharged'] ?>">
			<h3><?php if($combine) echo 'Combined ' ?>Order Items</h3>
			<ul>
			<?php foreach($detail['orderitems'] as $item) : ?>
			<li>
				<input type="hidden" 
					id="item-<?php echo $item['sku'] ?>"
					name="deets[]" 
					value="<?php echo $item['qty'] . '||' . $item['sku'] ?>">
				<a href="#" class="button markpacked">packed</a>
				<span>
				<span class="qty"><?php echo $item['qty'] ?></span> 
					x
				<?php echo $item['sku'] ?>
					-
				<?php echo $item['desc'] ?>
				</span>
				<a href="#" class="button removeitem">x</a>
			</li>
			<?php endforeach; ?>
			</ul>
			<hr>
		<?php endforeach;?>
		<?php else: ?>
			<hr>
			<p><strong>Could not find this transaction in the current journal. 
				Please upload a new journal within the correct time period.</strong></p>
			<hr>
		<?php endif; ?>
		<?php if($order['18.1']): ?>
		<h3 style="text-transform: uppercase">Remove Prices</h3>
		<hr>
		<?php endif; ?>
		<?php if($order['17']): ?>
		<strong>Hold until: <?php echo $order['17'] ?></strong>
		<hr>
		<?php endif; ?>
		Shipment Method: <strong><?php echo $order['9'] ?></strong>
		<hr>
		Notes: <br>
		<textarea name="notes" cols="30" rows="5"><?php echo $order["4"] ?></textarea>
		<br>

		</div>
		<div style="float: left; margin: 1%; padding: 1%; width: 46%;">
		<h3>Address</h3>
		First Name: <input type="text" name="first_name" value="<?php echo $order["14"] ?>"><br>
		Last Name: <input type="text" name="last_name" value="<?php echo $order["15"] ?>"><br>
		Company: <input type="text" name="company" value="<?php echo $order["12"] ?>"><br>
		Address 1: <input type="text" name="address_1" value="<?php echo $order["2.1"] ?>"><br>
		Address 2: <input type="text" name="address_2" value="<?php echo $order["2.2"] ?>"><br>
		City: <input type="text" name="city" value="<?php echo $order["2.3"] ?>"><br>
		State: <input size="8" type="text" name="state" value="<?php echo $order["2.4"] ?>"><br>
		Code: <input type="text" name="code" value="<?php echo $order["2.5"] ?>"><br>
		<?php 
		// WTF GravityForms? Can't use a country code? 
		if($order['2.6'] == 'United States') {
			$cunt = 'US';
		} elseif($order['2.6'] == 'Canada') {
			$cunt = 'CA';
		} else {
			$cunt = $order['2.6'];
		} 
		?>
		Country: <input type="text" name="country" value="<?php echo $cunt ?>"><br>
		Phone: <input type="text" name="phone" value="<?php echo $order["7"] ?>"><br>
		Email: <input type="text" name="email" value="<?php echo $order["3"] ?>"><br>
		</div>
		<div style="clear:both"></div>
		<button class="btn btn-success">Process Order</button>
		<?php if($order['17']): ?>
		</div>
		<div style="clear:both"></div>
		<?php endif ?>

	</form>
	<?php endforeach; ?>
	</div>
	<div style="float: left; margin: 1%; padding: 1%; width: 20%;">
	<h1><?php echo $howmany ?> Orders</h1>
	<p>You will need a "Transaction Journal.csv" spanning the dates: <?php echo $firstdate[0] . ' - ' . $lastdate[0] ?>.</p>
	<form action="/wp-content/plugins/store5-order-grinder/upload.php" method="post" enctype="multipart/form-data" class="up"> 
		<div class="form-group">
			<input type="file" name="myFile" id="myFile"> 
			<button type="submit" class="btn btn-lg btn-warning btn-block" value="Upload">
			Upload Transaction Journal
			</button>
		</div>
	</form>
	<!--	<h3>Instructions</h3>
		<p>In Merchant Back Office, run a <strong>Transaction Journal</strong> report with the following parameters:</p>
		<ul>
			<li>Date Posted should be between the newest and oldest orders</li>
			<li>Journal # &amp; Transaction # fields should both be 1 - 99999999</li>
			<li>Print Summary, Print Drawer Count &amp;Print Detail should all be checked</li>
		</ul>
		<p>When the report comes up, click the export button (very far upper-left). Change the file type to CSV and save it to your desktop.</p>
		<p>Once that's done, come back here, click "Choose File;" locate and "Open" the newly exported "Transaction Journal.csv;" Then click the 'Upload &hellip;' button. </p>-->

	</div>

<style>
.button {
	background: #FFF;
	border: 1px solid #333;
	border-radius: 2px;	
	display: inline-block;
	font-size: 8px;
	padding: 3px;
}
.hodor { display: none; }
{'fraction_non_alphanumeric': 0.20932334710743802, 'fraction_numerical': 0.01943440082644628, 'mean_word_length': 4.402511335891176, 'pattern_counts': {'":': 0, '<': 383, '<?xml version=': 0, '>': 391, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1239533', 'n_tokens_mistral': 6069, 'n_tokens_neox': 5501, 'n_words': 1519}