<?php
/*
  $Id: stats_monthly_sales.php,v 1.1 2007/04/17 07:11:22 ryu Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
  
  modified for Koshoten.net2
  http://www.koshoten.net/
*/

  require('includes/application_top.php');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/kn_stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table width="<?php echo BOX_WIDTH; ?>" class="knMenuBar">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
        </table></td>
<!-- body_text //-->
    <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"><?php echo HEADING_TITLE; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td valign="top"><table border="1" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td><?php echo TABLE_HEADING_MONTH; ?></td>
                <td align="right"><?php echo TABLE_HEADING_QUANTITY; ?></td>
                <td align="right"><?php echo TABLE_HEADING_SALES; ?>&nbsp;</td>
              </tr>
<?php
  $sales_query_raw = "select date_format(o.date_purchased, '%Y/%m') as order_month, sum(op.products_quantity) as order_quantity, sum(op.products_quantity * op.final_price) as ordersum from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o where o.orders_id = op.orders_id group by order_month order by order_month DESC";
  $sales_split = new splitPageResults($_GET['page'], 12, $sales_query_raw, $sales_query_numrows);
// fix counted customers
  $sales_query_numrows = tep_db_query("select date_format(date_purchased, '%Y/%m') as order_month from " . TABLE_ORDERS . " group by order_month");
  $sales_query_numrows = tep_db_num_rows($sales_query_numrows);

  $sales_query = tep_db_query($sales_query_raw);
  while ($sales = tep_db_fetch_array($sales_query)) {
?>
              <tr>
                <td><?php echo $sales['order_month']; ?></td>
                <td align="right"><?php echo $sales['order_quantity']; ?></td>
                <td align="right"><?php echo $currencies->format($sales['ordersum']); ?>&nbsp;</td>
              </tr>
<?php
  }
?>
            </table></td>
          </tr>
          <tr>
            <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="smallText" valign="top"><?php echo $sales_split->display_count($sales_query_numrows, 12, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_MONTHS); ?>&nbsp;</td>
                <td class="smallText" align="right"><?php echo $sales_split->display_links($sales_query_numrows, 12, MAX_DISPLAY_PAGE_LINKS, $_GET['page']); ?>&nbsp;</td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>