[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> stats_recover_cart_sales.php (source)

   1  <?php
   2  /*

   3  $Id: stats_recover_cart_sales.php 14 2006-07-28 17:42:07Z user $

   4    Recover Cart Sales Report v2.23

   5  

   6    contrib: JM Ivler 11/20/03

   7    (c) Ivler/ osCommerce

   8    http://oscdox.com

   9  

  10    Released under the GNU General Public License

  11  

  12  */
  13  
  14    require ('includes/application_top.php');
  15  
  16    require (DIR_WS_CLASSES . 'currencies.php');
  17    $currencies = new currencies();
  18  
  19    function tep_date_order_stat($raw_date) {
  20      if ($raw_date == '') return false;
  21      $year = substr($raw_date, 2, 2);
  22      $month = (int)substr($raw_date, 4, 2);
  23      $day = (int)substr($raw_date, 6, 2);
  24      return date(DATE_FORMAT, mktime(0, 0, 0, $month, $day, $year));
  25    }
  26  
  27  ?>
  28  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  29  <html <?php echo HTML_PARAMS; ?>>
  30  <head>
  31  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  32  <title><?php echo TITLE; ?></title>
  33  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  34  <script language="javascript" src="includes/menu.js"></script>
  35  </head>
  36  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
  37  
  38  <!-- header //-->
  39  
  40  <?php require (DIR_WS_INCLUDES . 'header.php'); ?>
  41  
  42  <!-- header_eof //-->
  43  
  44  <!-- body //-->
  45  <?php
  46  function seadate($day) {
  47   $ts = date("U");
  48   $rawtime = strtotime("-".$day." days", $ts);
  49   $ndate = date("Ymd", $rawtime);
  50  return $ndate;
  51  }
  52  ?>
  53  <table border="0" width="100%" cellspacing="2" cellpadding="2">
  54    <tr>
  55  <?php
  56          if ($menu_dhtml == false ) {     // add for dhtml_menu
  57              echo '<td width="' . BOX_WIDTH . '" valign="top">';
  58              echo '<table border="0" width="' . BOX_WIDTH . '" cellspacing="1" cellpadding="1" class="columnLeft">';
  59              echo '<!-- left_navigation //-->';
  60              require (DIR_WS_INCLUDES . 'column_left.php');
  61              echo '<!-- left_navigation_eof //-->';
  62              echo '</table>';
  63              echo '</td>';
  64          } else {
  65          }
  66  ?>
  67  <!-- body_text //-->
  68      <td width="100%" valign="top">
  69          <table border="0" width="100%" cellspacing="0" cellpadding="0">
  70  Working...
  71            <tr>
  72                <td colspan="6">
  73  <!-- new header -->
  74                    <table border="0" width="100%" cellspacing="0" cellpadding="2">
  75                      <tr>
  76                            <td class="pageHeading" align="left"><?php echo HEADING_TITLE; ?></td>
  77                            <td class="pageHeading" align="right">
  78                          <?php $tdate = $_POST['tdate'];
  79                              if ($tdate == '') $tdate = RCS_REPORT_DAYS;
  80                              $ndate = seadate($tdate); ?>
  81                          <form method=post action=<?php echo $PHP_SELF;?> >
  82                        <table align="right" width="100%">
  83                          <tr class="dataTableContent" align="right">
  84                            <td nowrap><?php echo DAYS_FIELD_PREFIX; ?><input type=text size=4 width=4 value=<?php echo $tdate; ?> name=tdate><?php echo DAYS_FIELD_POSTFIX; ?><input type=submit value="<?php echo DAYS_FIELD_BUTTON; ?>"></td>
  85                          </tr>
  86                        </table>
  87                          </form>
  88                        </td>
  89                      </tr>
  90                  </table>
  91                </td>
  92            </tr>
  93  <?php
  94      // Init vars

  95    $custknt = 0;
  96    $total_recovered = 0;
  97    $custlist = '';
  98  
  99      // Query database for abandoned carts within our timeframe

 100    $conquery = tep_db_query("select * from ". TABLE_SCART ." where dateadded >= '".$ndate."' order by dateadded DESC" );
 101    $rc_cnt = mysql_num_rows($conquery);
 102  
 103      // Loop though each one and process it

 104    for ($i = 0; $i < $rc_cnt; $i++)
 105    {
 106          $inrec = tep_db_fetch_array($conquery);
 107          $cid = $inrec['customers_id'];
 108  
 109          // we have to get the customer data in order to better locate matching orders

 110          $query1 = tep_db_query("select c.customers_firstname, c.customers_lastname from ".TABLE_CUSTOMERS." c where c.customers_id ='".$cid."'");
 111          $crec = tep_db_fetch_array($query1);
 112  
 113          // Query DB for the FIRST order that matches this customer ID and came after the abandoned cart

 114          $orders_query_raw = "select o.orders_id, o.customers_id, o.date_purchased, s.orders_status_name, ot.text as order_total, ot.value from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where (o.customers_id = " . (int)$cid . ' OR o.customers_email_address like "' . $crec['customers_email_address'] .'" OR o.customers_name like "' . $crec['customers_firstname'] . ' ' . $crec['customers_lastname'] . '") and o.orders_status > ' . RCS_PENDING_SALE_STATUS . ' and s.orders_status_id = o.orders_status and o.date_purchased >= "' . $inrec['dateadded'] . '" and ot.class = "ot_total"';
 115          $orders_query = tep_db_query($orders_query_raw);
 116          $orders = tep_db_fetch_array($orders_query);
 117  
 118          // If we got a match, create the table entry to display the information

 119          if( $orders )
 120          {
 121              $custknt++;
 122              $total_recovered += $orders['value'];
 123              $custknt % 2 ? $class = RCS_REPORT_EVEN_STYLE : $class = RCS_REPORT_ODD_STYLE;
 124              $custlist .= "<tr class=".$class.">".
 125                          "<td class=datatablecontent align=right>".$inrec['scartid']."</td>".
 126                          "<td>&nbsp;</td>".
 127                          "<td class=datatablecontent align=center>".tep_date_order_stat($inrec['dateadded'])."</td>".
 128                          "<td>&nbsp;</td>".
 129                          "<td class=datatablecontent><a href='" . tep_href_link(FILENAME_CUSTOMERS, 'search=' . $crec['customers_lastname'], 'NONSSL') . "'>".$crec['customers_firstname']." ".$crec['customers_lastname']."</a></td>".
 130                          "<td class=datatablecontent>".tep_date_short($orders['date_purchased'])."</td>".
 131                          "<td class=datatablecontent align=center>".$orders['orders_status_name']."</td>".
 132                          "<td class=datatablecontent align=right>".strip_tags($orders['order_total'])."</td>".
 133                          "<td>&nbsp;</td>".
 134                          "</tr>";
 135          }
 136      }
 137    $cline =  "<tr><td height=\"15\" COLSPAN=8> </td></tr>".
 138                    "<tr>".
 139                      "<td align=right COLSPAN=3 class=main><b>". TOTAL_RECORDS ."</b></td>".
 140                      "<td>&nbsp;</td>".
 141                      "<td align=left COLSPAN=5 class=main>". $rc_cnt ."</td>".
 142                  "</tr>".
 143                  "<tr>".
 144                      "<td align=right COLSPAN=3 class=main><b>". TOTAL_SALES ."</b></td>".
 145                      "<td>&nbsp;</td>".
 146                      "<td align=left COLSPAN=5 class=main>". $custknt . TOTAL_SALES_EXPLANATION ." </td>".
 147                  "</tr>".
 148                  "<tr><td height=\"12\" COLSPAN=6> </td></tr>";
 149     echo $cline;
 150  ?>
 151               <tr class="dataTableHeadingRow">    <!-- Header -->
 152                <td width="7%" class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_SCART_ID ?></td>
 153                <td width="1%" class="dataTableHeadingContent">&nbsp;</td>
 154                <td width="10%" class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_SCART_DATE ?></td>
 155                <td width="1%" class="dataTableHeadingContent">&nbsp;</td>
 156                <td width="50%" class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMER ?></td>
 157                <td width="10%" class="dataTableHeadingContent"><?php echo TABLE_HEADING_ORDER_DATE ?></td>
 158                <td width="10%" class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_ORDER_STATUS ?></td>
 159                <td width="10%" class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ORDER_AMOUNT ?></td>
 160                <td width="1%" class="dataTableHeadingContent">&nbsp;</td>
 161            </tr>
 162  <?php
 163     echo $custlist;    // BODY: <tr> sections with recovered cart data

 164  ?>
 165          <tr>
 166                  <td colspan=9 valign="bottom"><hr width="100%" size="1" color="#800000" noshade></td>
 167               </tr>
 168          <tr class="main">
 169            <td align="right" valign="center" colspan=4 class="main"><b><?php echo TOTAL_RECOVERED ?>&nbsp;</b></font></td>
 170            <td align=left colspan=3 class="main"><b><?php echo $rc_cnt ? tep_round(($custknt / $rc_cnt) * 100, 2) : 0 ?>%</b></font></td>
 171            <td class="main" align="right"><b><?php echo $currencies->format(tep_round($total_recovered, 2)) ?></b></font></td>
 172            <td class="main">&nbsp;</td>
 173          </tr>
 174  Done!
 175      </table>
 176  <!-- body_text_eof //-->
 177      </td>
 178   </tr>
 179  </table>
 180  <!-- body_eof //-->
 181  
 182  <!-- footer //-->
 183  
 184  <?php require (DIR_WS_INCLUDES . 'footer.php'); ?>
 185  
 186  <!-- footer_eof //-->
 187  
 188  <br>
 189  </body>
 190  </html>
 191  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7