function do_sales_report()
    {
        global $wpdb;
        $trnsid = 1;
        $gateway_accounts = get_option('pbci_gateway_accounts', array());
        $export_accounts = get_option('pbci_export_accounts', array('sales_revenue' => 'Product Revenue', 'shipping' => 'Shipping', 'sales_tax_account' => 'Sales Tax Payable', 'sales_tax_payee' => 'Sales Tax'));
        $periods = array_keys($_POST['period']);
        $period_count = 0;
        $grand_total_items = 0;
        $grand_total_item_taxable = 0;
        $grand_total_item_non_taxable = 0;
        $grand_total_discounts = 0;
        $grand_total_discount_taxable = 0;
        $grand_total_discount_non_taxable = 0;
        $grand_total_shipping_transasctions = 0;
        $grand_total_shipping_taxable = 0;
        $grand_total_shipping_non_taxable = 0;
        $grand_total_tax_transactions = 0;
        $grand_total_tax_taxable = 0;
        $grand_total_tax_non_taxable = 0;
        $grand_total_transactions = 0;
        $grand_total_transaction_total_taxable = 0;
        $grand_total_transaction_total_non_taxable = 0;
        ob_start();
        foreach ($periods as $period) {
            $a = explode('-', $period);
            $year = $a[0];
            $month = $a[1];
            $period_count++;
            $sql = "SELECT ID FROM " . WPSC_TABLE_PURCHASE_LOGS . ' WHERE MONTH( FROM_UNIXTIME( date ) ) = ' . $month . ' AND YEAR( FROM_UNIXTIME( DATE ) ) = ' . $year . ' ORDER by date DESC';
            $result = $wpdb->get_col($sql, 0);
            $purchase_log_ids = array_map('intval', $result);
            $datestring = date("F Y", mktime(0, 0, 0, $month, 1, $year));
            $items = 0;
            $item_taxable = 0;
            $item_non_taxable = 0;
            $discounts = 0;
            $discount_taxable = 0;
            $discount_non_taxable = 0;
            $shipping_transasctions = 0;
            $shipping_taxable = 0;
            $shipping_non_taxable = 0;
            $tax_transactions = 0;
            $tax_taxable = 0;
            $tax_non_taxable = 0;
            $transactions = 0;
            $transaction_total_taxable = 0;
            $transaction_total_non_taxable = 0;
            $taxable_transactions = 0;
            $this_transaction_item_total = 0;
            $taxable_total = 0;
            $not_taxable_transactions = 0;
            $not_taxable_total = 0;
            $max_rows = 1;
            foreach ($purchase_log_ids as $purchase_log_id) {
                $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
                $gateway_id = $purchase_log->get('gateway');
                $data = $purchase_log->get_data();
                //				if ( empty( $gateway_accounts[$gateway_id] ) ) {
                //					continue;
                //				}
                if ($purchase_log->is_incomplete_sale()) {
                    continue;
                }
                if ($purchase_log->is_payment_declined()) {
                    continue;
                }
                if ($purchase_log->is_refunded()) {
                    continue;
                }
                if ($purchase_log->is_refund_pending()) {
                    continue;
                }
                //				if ( ($purchase_log->get('processed') != WPSC_Purchase_Log::ACCEPTED_PAYMENT) && ($purchase_log->get('processed') != WPSC_Purchase_Log::CLOSED_ORDER) ) {
                //					continue;
                //				}
                $checkout_form_data = new WPSC_Checkout_Form_Data($purchase_log_id);
                $checkout = $checkout_form_data->get_data();
                $timestamp = $purchase_log->get('date');
                $thedate = date('m/d/Y', $timestamp);
                $transactions++;
                $t = floatval($purchase_log->get('wpec_taxes_total'));
                if ($t > 0) {
                    $is_taxable = true;
                    $taxable_transactions++;
                    $taxable_total += $this_transaction_item_total - $d;
                } else {
                    $is_taxable = false;
                    $not_taxable_transactions++;
                    $not_taxable_total += $this_transaction_item_total - $d;
                }
                if ($is_taxable) {
                    $transaction_total_taxable += $purchase_log->get('totalprice');
                } else {
                    $transaction_total_non_taxable += $purchase_log->get('totalprice');
                }
                $t = floatval($purchase_log->get('wpec_taxes_total'));
                if ($is_taxable) {
                    $tax_transactions++;
                    if ($is_taxable) {
                        $tax_taxable += $t;
                    } else {
                        $tax_non_taxable += $t;
                    }
                }
                $cart_contents = $purchase_log->get_cart_contents();
                foreach ($cart_contents as $cart_item) {
                    $items = $items + $cart_item->quantity;
                    $this_transaction_item_total = $cart_item->price * $cart_item->quantity;
                    if ($is_taxable) {
                        $item_taxable += $this_transaction_item_total;
                    } else {
                        $item_non_taxable += $this_transaction_item_total;
                    }
                }
                $s = floatval($purchase_log->get('total_shipping'));
                if ($s != 0) {
                    $shipping_transasctions++;
                    if ($is_taxable) {
                        $shipping_taxable += $s;
                    } else {
                        $shipping_non_taxable += $s;
                    }
                }
                $d = floatval($purchase_log->get('discount_value'));
                if ($d > 0) {
                    $discounts++;
                    if ($is_taxable) {
                        $discount_taxable += $d;
                    } else {
                        $discount_non_taxable += $d;
                    }
                }
                $t = floatval($purchase_log->get('wpec_taxes_total'));
                if ($t > 0) {
                    $taxable_transactions++;
                    $taxable_total += $this_transaction_item_total - $d;
                } else {
                    $not_taxable_transactions++;
                    $not_taxable_total += $this_transaction_item_total - $d;
                }
            }
            $grand_total_items += $items;
            $grand_total_item_taxable += $item_taxable;
            $grand_total_item_non_taxable += $item_non_taxable;
            $grand_total_discounts += $discounts;
            $grand_total_discount_taxable += $discount_taxable;
            $grand_total_discount_non_taxable += $discount_non_taxable;
            $grand_total_shipping_transasctions += $shipping_transasctions;
            $grand_total_shipping_taxable += $shipping_taxable;
            $grand_total_shipping_non_taxable += $shipping_non_taxable;
            $grand_total_tax_transactions += $tax_transactions;
            $grand_total_tax_taxable += $tax_taxable;
            $grand_total_tax_non_taxable += $tax_non_taxable;
            $grand_total_transactions += $transactions;
            $grand_total_transaction_total_taxable += $transaction_total_taxable;
            $grand_total_transaction_total_non_taxable += $transaction_total_non_taxable;
            ?>

			<table class="rounded-corner">
				<tr>
					<th>
						<?php 
            echo $datestring;
            ?>
					</th>
					<th>
						#
					</th>

					<th>
						taxable
					</th>

					<th>
						non-taxable
					</th>

					<th>
						total
					</th>
				</tr>


				<tr>
					<td>
						items
					</td>
					<td>
						<?php 
            echo $items;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($item_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($item_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($item_taxable + $item_non_taxable, 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						discounts
					</td>
					<td>
						<?php 
            echo $discounts;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($discount_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($discount_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($discount_non_taxable + $discount_taxable, 2);
            ?>
					</td>
				</tr>


				<tr>
					<td>
						net sales
					</td>
					<td>
						<?php 
            echo $items;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($item_taxable - $discount_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($item_non_taxable - $discount_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($item_taxable + $item_non_taxable - ($discount_non_taxable + $discount_taxable), 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						tax collected
					</td>
					<td>
						<?php 
            echo $tax_transactions;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($tax_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($tax_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($tax_non_taxable + $tax_taxable, 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						shipping
					</td>
					<td>
						<?php 
            echo $shipping_transasctions;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($shipping_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($shipping_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($shipping_non_taxable + $shipping_taxable, 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						transactions
					</td>
					<td>
						<?php 
            echo $transactions;
            ?>
					</td>
					<td>
						$<?php 
            echo number_format($transaction_total_taxable, 2);
            ?>
					</td>
					<td>
						$<?php 
            echo number_format($transaction_total_non_taxable, 2);
            ?>
					</td>
					<td>
						$<?php 
            echo number_format($transaction_total_non_taxable + $transaction_total_taxable, 2);
            ?>
					</td>

				</tr>


			</table>
			<br>
			<?php 
            if ($period_count > 0) {
                ?>
			<style>
			.rounded-corner {
					font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
					font-size: 12px;
					width: 480px;
					text-align: left;
					border-collapse: collapse;
					margin: 20px;
					}
			.rounded-corner th {
					font-weight: normal;
					font-size: 13px;
					color: #039;
					background: #b9c9fe;
					padding: 8px;
					}
			.rounded-corner td {
					background: #e8edff;
					border-top: 1px solid #fff;
					color: #669;
					padding: 8px;
					}
			</style>
			<?php 
            }
        }
        $details = ob_get_clean();
        if ($period_count > 1) {
            ?>
			<table class="rounded-corner">
				<tr>
					<th>
						Summary
					</th>
					<th>
						#
					</th>

					<th>
						taxable
					</th>

					<th>
						non-taxable
					</th>

					<th>
						total
					</th>
				</tr>


				<tr>
					<td>
						items
					</td>
					<td>
						<?php 
            echo $grand_total_items;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_item_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_item_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_item_taxable + $grand_total_item_non_taxable, 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						discounts
					</td>
					<td>
						<?php 
            echo $grand_total_discounts;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_discount_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_discount_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_discount_non_taxable + $grand_total_discount_taxable, 2);
            ?>
					</td>
				</tr>


				<tr>
					<td>
						net sales
					</td>
					<td>
						<?php 
            echo $grand_total_items;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_item_taxable - $grand_total_discount_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_item_non_taxable - $grand_total_discount_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_item_taxable + $grand_total_item_non_taxable - ($grand_total_discount_non_taxable + $grand_total_discount_taxable), 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						tax collected
					</td>
					<td>
						<?php 
            echo $grand_total_tax_transactions;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_tax_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_tax_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_tax_non_taxable + $grand_total_tax_taxable, 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						shipping
					</td>
					<td>
						<?php 
            echo $grand_total_shipping_transasctions;
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_shipping_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_shipping_non_taxable, 2);
            ?>
					</td>

					<td>
						$<?php 
            echo number_format($grand_total_shipping_non_taxable + $grand_total_shipping_taxable, 2);
            ?>
					</td>
				</tr>

				<tr>
					<td>
						transactions
					</td>
					<td>
						<?php 
            echo $grand_total_transactions;
            ?>
					</td>
					<td>
						$<?php 
            echo number_format($grand_total_transaction_total_taxable, 2);
            ?>
					</td>
					<td>
						$<?php 
            echo number_format($grand_total_transaction_total_non_taxable, 2);
            ?>
					</td>
					<td>
						$<?php 
            echo number_format($grand_total_transaction_total_non_taxable + $grand_total_transaction_total_taxable, 2);
            ?>
					</td>
				</tr>

			</table>
			<br>
			<?php 
        }
        echo $details;
    }