Frank - thanks for a great add on.
It is time to pay sales tax to the state, so it would be nice to have an option to report only sales that were local and have sales tax.
These are my modifications to do this. If there is a more elegant method, let us know.
In the language file stats_sales_report.php ~line 207 - added:
Code:
// checkboxes
define('CHECKBOX_SALES_TAX', 'Only Orders with Sales Tax');
In Classes file sales_report.php near top of file added variable $sales_tax:
Code:
class sales_report {
var $timeframe_group, $sd, $ed, $sd_raw, $ed_raw, $date_target, $date_status;
var $payment_method, $current_status, $manufacturer, $sales_tax, $detail_level, $output_format;
var $timeframe, $timeframe_id, $current_date, $product_filter;
function sales_report($timeframe, $sd, $ed, $date_target, $date_status, $payment_method, $current_status, $manufacturer, $sales_tax, $detail_level, $output_format, $order_total_validation) {
global $db;
// place passed variables into class variables
$this->timeframe_group = $timeframe;
$this->date_target = $date_target;
$this->date_status = $date_status;
$this->payment_method = $payment_method;
$this->current_status = $current_status;
$this->manufacturer = $manufacturer;
$this->sales_tax = $sales_tax;
$this->detail_level = $detail_level;
$this->output_format = $output_format;
$this->order_total_validation = $order_total_validation;
In Classes file sales_report.php near line 165 modify SQL query to include extra if else block. Else statement contains original query.
Code:
// build the SQL query of order numbers within the current timeframe
if ($this->sales_tax =="true"){ // if else statement added to sort only items that have sales tax. 7/16/10
$sql = "SELECT DISTINCT o.orders_id from " . TABLE_ORDERS . " o \n";
if ($this->date_target == 'status') {
$sql .= "LEFT JOIN " . TABLE_ORDERS_STATUS_HISTORY . " osh ON o.orders_id = osh.orders_id \n";
$sql .= "WHERE osh.date_added >= '" . date("Y-m-d H:i:s", $sd) . "' AND osh.date_added < '" . date("Y-m-d H:i:s", $ed) . "' \n";
$sql .= "AND order_tax != '$0.00' \n";
$sql .= "AND osh.orders_status_id = '" . $this->date_status . "' \n";
}
else {
$sql .= "WHERE o.date_purchased >= '" . date("Y-m-d H:i:s", $sd) . "' AND o.date_purchased < '" . date("Y-m-d H:i:s", $ed) . "' \n";
$sql .= "AND order_tax != '$0.00' \n";
}
if ($this->payment_method) $sql .= "AND o.payment_module_code LIKE '" . $this->payment_method . "' \n";
if ($this->current_status) $sql .= "AND o.orders_status = '" . $this->current_status . "' \n";
$sql .= "ORDER BY o.orders_id DESC";
}
else {
// start of original SQL query.
$sql = "SELECT DISTINCT o.orders_id from " . TABLE_ORDERS . " o \n";
if ($this->date_target == 'status') {
$sql .= "LEFT JOIN " . TABLE_ORDERS_STATUS_HISTORY . " osh ON o.orders_id = osh.orders_id \n";
$sql .= "WHERE osh.date_added >= '" . date("Y-m-d H:i:s", $sd) . "' AND osh.date_added < '" . date("Y-m-d H:i:s", $ed) . "' \n";
$sql .= "AND osh.orders_status_id = '" . $this->date_status . "' \n";
}
else {
$sql .= "WHERE o.date_purchased >= '" . date("Y-m-d H:i:s", $sd) . "' AND o.date_purchased < '" . date("Y-m-d H:i:s", $ed) . "' \n";
}
if ($this->payment_method) $sql .= "AND o.payment_module_code LIKE '" . $this->payment_method . "' \n";
if ($this->current_status) $sql .= "AND o.orders_status = '" . $this->current_status . "' \n";
$sql .= "ORDER BY o.orders_id DESC";
// end of orgiginal SQL query
Modified stats_sales_report.php to add check box to top section of page
Add around line 174
Code:
$sales_tax= ($_GET['sales_tax'] != '' ? $_GET['sales_tax'] : false);
Pass new variable to function:
Code:
$sr = new sales_report($timeframe, //* determines how sales tallies are grouped
$start_date, $end_date, //* the date range
$date_target, $date_status, //* what date field to search, and the status (if needed)
$payment_method, // payment method used for desired orders
$current_status, // currently assigned status to the order
$manufacturer, // only include orders with assigned manufacturer
$sales_tax, //Added to find items with sales tax
$detail_level, //* what information to output
$output_format, //* how to display the results
$order_total_validation);
Check Box added above middle radio buttons around line 449
Code:
<td class="smallText">
<input type="checkbox" name="sales_tax" value="true"> <?php echo CHECKBOX_SALES_TAX; ?> <br />
<input type="radio" name="date_target" value="purchased" onClick="hide('td_date_status', true)"><?php echo RADIO_DATE_TARGET_PURCHASED; ?><br />
<input type="radio" name="date_target" value="status" onClick="show('td_date_status')"><?php echo RADIO_DATE_TARGET_STATUS; ?> </td>
I think that was all the changes. Seems to work fine.
Bookmarks