Code:
<?php
/**
* /public_html/store/admin/export.php
*
* Export invoice data from Zend to Microsoft Excel CSV
*
* @author Ahmed Chafik <ajchafik######################>
* @copyright Cyberscraps 2006
* @version Define("Id: export.php,v 1 2006/06/21 21:24:53 Ahmed")
*
* Released under the terms and conditions of the
* GNU General Public License (Version 2)
*
*/
require('includes/application_top.php');
require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();
if( isset($_POST['download_csv']) ) {
Header('Content-type: application/csv');
Header("Content-disposition: attachment; filename=\"Payments".date('mdy-Hi').".csv\"");
$order = $db->execute("SELECT orders_id, date_purchased, customers_state,
customers_name, order_tax, order_total
FROM ". TABLE_ORDERS ."
WHERE downloaded='no'
ORDER BY orders_id ASC");
echo "Invoice No.,Date,State,Customer Name,Tax,Total (excluding tax),Total (including tax)\n";
while( !$order->EOF ) {
list( $invoice, $date, $state, $name, $tax, $total ) = array_values($order->fields);
$get_tax = ((($total-5)/($total-5-$tax))-1)*100;
preg_match('/^[0-9]{2}([0-9]{2})\-([0-9]{2})\-([0-9]{2}) .+$/', $date, $args);
list( $year, $month ) = $args;
echo "$invoice,".
"$month/$year,\"$state\",\"$name\",\"".
zen_display_tax_value($get_tax, true).'%","'.
$currencies->format($total-$tax).'","'.
$currencies->format($total)."\"\n";
$order->MoveNext();
}
$db->execute('UPDATE '. TABLE_ORDERS .' SET downloaded="yes" WHERE downloaded="no"');
exit;
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?= HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= CHARSET; ?>">
<title><?= TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript">
<!--
function init()
{
cssjsmenu('navbar');
if (document.getElementById)
{
var kill = document.getElementById('hoverJS');
kill.disabled = true;
}
}
// -->
</script>
</head>
<body onLoad="init()">
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading">Order History</td>
<td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
</tr>
</table></td>
</tr>
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent">Invoice No.</td>
<td class="dataTableHeadingContent">Date</td>
<td class="dataTableHeadingContent">State</td>
<td class="dataTableHeadingContent">Customer Name</td>
<td class="dataTableHeadingContent">Tax</td>
<td class="dataTableHeadingContent">Total (excluding tax)</td>
<td class="dataTableHeadingContent" align="right">Total (including tax) </td>
</tr>
<?php
$query = "SELECT orders_id, date_purchased, customers_state,
customers_name, order_tax, order_total
FROM ". TABLE_ORDERS ."
ORDER BY orders_id ASC";
$query = strtolower($query);
$order_pages = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS_REPORTS, $query, $rows);
$order = $db->execute($query);
while( !$order->EOF ) {
list( $invoice, $date, $state, $name, $tax, $total ) = array_values($order->fields);
$get_tax = ((($total-5)/($total-5-$tax))-1)*100;
?>
<tr class="dataTableRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" onClick="window.open('<?= zen_href_link(FILENAME_ORDERS_INVOICE, 'oID=' . $invoice, 'NONSSL'); ?>')">
<td class="dataTableContent" align="right"><?= $invoice; ?> </td>
<td class="dataTableContent"><?= zen_date_long($date) ?></td>
<td class="dataTableContent"><?= $state ?></td>
<td class="dataTableContent"><?= $name ?></td>
<td class="dataTableContent"><?= zen_display_tax_value($get_tax, true) ?>%</td>
<td class="dataTableContent"><?= $currencies->format($total-$tax); ?></td>
<td class="dataTableContent" align="right"><?= $currencies->format($total); ?> </td>
</tr>
<?php
$order->MoveNext();
}
if( !isset($invoice) ) {
?>
<tr class="dataTableRow">
<td class="dataTableContent" align="center" colspan="7"><b>No orders were found!</b></td>
</tr>
<?
}
?>
</table></td>
</tr>
<tr>
<td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<td class="smallText" valign="top"><?php echo $order_pages->display_count($rows, MAX_DISPLAY_SEARCH_RESULTS_REPORTS, $_GET['page'], 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> orders)'); ?></td>
<td class="smallText" align="right"><?php echo $order_pages->display_links($rows, MAX_DISPLAY_SEARCH_RESULTS_REPORTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page']); ?></td>
</tr>
</td>
<td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td class="smallText" align="right">
<form name="download_csv" method="post">
<input style="font-weight: bold" name="download_csv" type="submit" value="Export to Excel Spreadsheet" />
</form>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
all i'm trying to do is get the invoice number, date, province, tax exported then i can do the rest in excell
Bookmarks