return;
        }
        ?>
		</table>
	<?php 
    }
    ?>
	
	<table class="productcart">
	<?php 
    if (wpsc_cart_tax(false) > 0) {
        ?>
		<tr class="total_price total_tax">
			<td colspan="3">
				<?php 
        echo wpsc_display_tax_label(true);
        ?>

			</td>
			<td colspan="2">
				<span id="checkout_tax" class="pricedisplay checkout-tax"><?php 
        echo wpsc_cart_tax();
        ?>
</span>
			</td>
		</tr>
	<?php 
    }
    ?>
	  <?php 
    if (wpsc_uses_coupons() && wpsc_coupon_amount(false) > 0) {
function wpsc_packing_slip($purchase_id)
{
    global $wpdb, $purchlogitem, $wpsc_cart, $purchlog;
    if (isset($_REQUEST['purchaselog_id'])) {
        $purchlogitem = new wpsc_purchaselogs_items((int) $_REQUEST['purchaselog_id']);
    }
    $purch_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='" . $purchase_id . "'";
    $purch_data = $wpdb->get_row($purch_sql, ARRAY_A);
    //echo "<p style='padding-left: 5px;'><strong>".__('Date', 'wpsc')."</strong>:".date("jS M Y", $purch_data['date'])."</p>";
    $cartsql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_id . "";
    $cart_log = $wpdb->get_results($cartsql, ARRAY_A);
    $j = 0;
    if ($cart_log != null) {
        echo "<div class='packing_slip'>\n\r";
        echo apply_filters('wpsc_packing_slip_header', '<h2>' . __('Packing Slip', 'wpsc') . "</h2>\n\r");
        echo "<strong>" . __('Order', 'wpsc') . " #</strong> " . $purchase_id . "<br /><br />\n\r";
        echo "<table>\n\r";
        /*
        		
        			$form_sql = "SELECT * FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE  `log_id` = '".(int)$purchase_id."'";
        			$input_data = $wpdb->get_results($form_sql,ARRAY_A);
        */
        echo "<tr class='heading'><td colspan='2'><strong>Billing Info</strong></td></tr>";
        foreach ((array) $purchlogitem->userinfo as $userinfo) {
            if ($userinfo['unique_name'] != 'billingcountry') {
                echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
            } else {
                $userinfo['value'] = maybe_unserialize($userinfo['value']);
                if (is_array($userinfo['value'])) {
                    if (!empty($userinfo['value'][1]) && !is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . $userinfo['value'][1] . "</td></tr>";
                    } elseif (is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . wpsc_get_state_by_id($userinfo['value'][1], 'name') . "</td></tr>";
                    }
                    if (!empty($userinfo['value'][0])) {
                        echo "<tr><td>Country: </td><td>" . $userinfo['value'][0] . "</td></tr>";
                    }
                } else {
                    echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
                }
            }
        }
        echo "<tr class='heading'><td colspan='2'><strong>Shipping Info</strong></td></tr>";
        foreach ((array) $purchlogitem->shippinginfo as $userinfo) {
            if ($userinfo['unique_name'] != 'shippingcountry' && $userinfo['unique_name'] != 'shippingstate') {
                echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
            } elseif ($userinfo['unique_name'] == 'shippingcountry') {
                $userinfo['value'] = maybe_unserialize($userinfo['value']);
                if (is_array($userinfo['value'])) {
                    if (!empty($userinfo['value'][1]) && !is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . $userinfo['value'][1] . "</td></tr>";
                    } elseif (is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . wpsc_get_state_by_id($userinfo['value'][1], 'name') . "</td></tr>";
                    }
                    if (!empty($userinfo['value'][0])) {
                        echo "<tr><td>Country: </td><td>" . $userinfo['value'][0] . "</td></tr>";
                    }
                } else {
                    echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
                }
            } elseif ($userinfo['unique_name'] == 'shippingstate') {
                if (!empty($userinfo['value']) && !is_numeric($userinfo['value'])) {
                    echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td</tr>>";
                } elseif (is_numeric($userinfo['value'])) {
                    echo "<tr><td>State: </td><td>" . wpsc_get_state_by_id($userinfo['value'], 'name') . "</td></tr>";
                }
            }
        }
        //		echo('<pre>'.print_r($purchlogitem,true).'</pre>');
        /*
        	foreach($input_data as $input_row) {
        			  $rekeyed_input[$input_row['form_id']] = $input_row;
        			}
        			
        			
        			if($input_data != null) {
                $form_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1'",ARRAY_A);
            // exit('<pre>'.print_r($purch_data, true).'</pre>');
                foreach($form_data as $form_field) {
                  switch($form_field['type']) {
        			case 'country':
        
        						$delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `".WPSC_TABLE_REGION_TAX."` AS `regions` INNER JOIN `".WPSC_TABLE_CURRENCY_LIST."` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('".$wpdb->escape( $purch_data['billing_country'])."')");
        
                    if(is_numeric($purch_data['billing_region']) && ($delivery_region_count > 0)) {
                      echo "  <tr><td>".__('State', 'wpsc').":</td><td>".wpsc_get_region($purch_data['billing_region'])."</td></tr>\n\r";
                    }
                    echo "  <tr><td>".wp_kses($form_field['name'], array() ).":</td><td>".wpsc_get_country($purch_data['billing_country'])."</td></tr>\n\r";
                    break;
                        
                    case 'delivery_country':
                    echo "  <tr><td>".$form_field['name'].":</td><td>".wpsc_get_country($purch_data['shipping_country'])."</td></tr>\n\r";
                    break;
                        
                    case 'heading':
                    echo "  <tr><td colspan='2'><strong>".wp_kses($form_field['name'], array()).":</strong></td></tr>\n\r";
                    break;
                    
                    default:
                    if($form_field['unique_name'] == 'shippingstate'){
                    	echo "  <tr><td>".wp_kses($form_field['name'], array() ).":</td><td>".wpsc_get_region($purch_data['shipping_region'])."</td></tr>\n\r";
                    }else{
                    	echo "  <tr><td>".wp_kses($form_field['name'], array() ).":</td><td>".htmlentities(stripslashes($rekeyed_input[$form_field['id']]['value']), ENT_QUOTES,'UTF-8')."</td></tr>\n\r";
                    }
                    break;
                  }
                }
        			} else {
                echo "  <tr><td>".__('Name', 'wpsc').":</td><td>".$purch_data['firstname']." ".$purch_data['lastname']."</td></tr>\n\r";
                echo "  <tr><td>".__('Address', 'wpsc').":</td><td>".$purch_data['address']."</td></tr>\n\r";
                echo "  <tr><td>".__('Phone', 'wpsc').":</td><td>".$purch_data['phone']."</td></tr>\n\r";
                echo "  <tr><td>".__('Email', 'wpsc').":</td><td>".$purch_data['email']."</td></tr>\n\r";
        			}
        */
        if (get_option('payment_method') == 2) {
            $gateway_name = '';
            foreach ($GLOBALS['nzshpcrt_gateways'] as $gateway) {
                if ($purch_data['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
            }
        }
        // 			echo "  <tr><td colspan='2'></td></tr>\n\r";
        // 			echo "  <tr><td>".__('Payment Method', 'wpsc').":</td><td>".$gateway_name."</td></tr>\n\r";
        // 			//echo "  <tr><td>".__('Purchase No.', 'wpsc').":</td><td>".$purch_data['id']."</td></tr>\n\r";
        // 			echo "  <tr><td>".__('How The Customer Found Us', 'wpsc').":</td><td>".$purch_data['find_us']."</td></tr>\n\r";
        // 			$engrave_line = explode(",",$purch_data['engravetext']);
        // 			echo "  <tr><td>".__('Engrave text', 'wpsc')."</td><td></td></tr>\n\r";
        // 			echo "  <tr><td>".__('Line 1', 'wpsc').":</td><td>".$engrave_line[0]."</td></tr>\n\r";
        // 			echo "  <tr><td>".__('Line 2', 'wpsc').":</td><td>".$engrave_line[1]."</td></tr>\n\r";
        // 			if($purch_data['transactid'] != '') {
        // 				echo "  <tr><td>".__('Transaction Id', 'wpsc').":</td><td>".$purch_data['transactid']."</td></tr>\n\r";
        // 			}
        echo "</table>\n\r";
        echo "<table class='packing_slip'>";
        echo "<tr>";
        echo " <th>" . __('Quantity', 'wpsc') . " </th>";
        echo " <th>" . __('Name', 'wpsc') . "</th>";
        echo " <th>" . __('Price', 'wpsc') . " </th>";
        echo " <th>" . __('Shipping', 'wpsc') . " </th>";
        echo "<th>" . wpsc_display_tax_label(false) . "</th>";
        echo '</tr>';
        $endtotal = 0;
        $all_donations = true;
        $all_no_shipping = true;
        $file_link_list = array();
        //			exit('<pre>'.print_r($cart_log,true).'</pre>');
        foreach ($cart_log as $cart_row) {
            $purchlogitem->the_purch_item();
            //			exit('<pre>'.print_r, true).'</pre>');
            $alternate = "";
            $j++;
            if ($j % 2 != 0) {
                $alternate = "class='alt'";
            }
            $productsql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $cart_row['prodid'] . "";
            $product_data = $wpdb->get_results($productsql, ARRAY_A);
            $variation_sql = "SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='" . $cart_row['id'] . "'";
            $variation_data = $wpdb->get_results($variation_sql, ARRAY_A);
            $variation_count = count($variation_data);
            if ($variation_count > 1) {
                $variation_list = " (";
                $i = 0;
                foreach ($variation_data as $variation) {
                    if ($i > 0) {
                        $variation_list .= ", ";
                    }
                    $value_id = $variation['value_id'];
                    $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                    $variation_list .= $value_data[0]['name'];
                    $i++;
                }
                $variation_list .= ")";
            } else {
                if ($variation_count == 1) {
                    $value_id = $variation_data[0]['value_id'];
                    $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                    $variation_list = " (" . $value_data[0]['name'] . ")";
                } else {
                    $variation_list = '';
                }
            }
            if ($cart_row['donation'] != 1) {
                $all_donations = false;
            }
            if ($cart_row['no_shipping'] != 1) {
                $shipping = $cart_row['pnp'] * $cart_row['quantity'];
                $total_shipping += $shipping;
                $all_no_shipping = false;
            } else {
                $shipping = 0;
            }
            $price = $cart_row['price'] * $cart_row['quantity'];
            $gst = $price - $price / (1 + $cart_row['gst'] / 100);
            if ($gst > 0) {
                $tax_per_item = $gst / $cart_row['quantity'];
            }
            echo "<tr {$alternate}>";
            echo " <td>";
            echo $cart_row['quantity'];
            echo " </td>";
            echo " <td>";
            echo $product_data[0]['name'];
            echo stripslashes($variation_list);
            echo " </td>";
            echo " <td>";
            echo nzshpcrt_currency_display($price, 1);
            echo " </td>";
            echo " <td>";
            echo nzshpcrt_currency_display($shipping, 1);
            echo " </td>";
            echo '<td>';
            if (wpsc_tax_isincluded()) {
                echo wpsc_purchaselog_details_tax();
            } else {
                echo nzshpcrt_currency_display($cart_row['tax_charged'], 1);
            }
            echo '<td>';
            echo '</tr>';
        }
        echo "</table>";
        echo '<table class="packing-slip-totals">';
        echo '<tr><th>Base Shipping</th><td>' . nzshpcrt_currency_display($purch_data['base_shipping'], 1) . '</td></tr>';
        echo '<tr><th>Total Shipping</th><td>' . nzshpcrt_currency_display($purch_data['base_shipping'] + $total_shipping, 1) . '</td></tr>';
        echo '<tr><th>Total Price</th><td>' . nzshpcrt_currency_display($purch_data['totalprice'], 1) . '</td></tr>';
        echo '</table>';
        echo "</div>\n\r";
    } else {
        echo "<br />" . __('This users cart was empty', 'wpsc');
    }
}