[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> affiliate_payment.php (source)

   1  <?php
   2  /*

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

   4  

   5    OSC-Affiliate

   6  

   7    Contribution based on:

   8  

   9    osCMax Power E-Commerce

  10    http://oscdox.com

  11  

  12    Copyright 2006 osCMax

  13  

  14    Released under the GNU General Public License

  15  */
  16  
  17    require ('includes/application_top.php');
  18  
  19    require (DIR_WS_CLASSES . 'currencies.php');
  20    $currencies = new currencies();
  21  
  22    $payments_statuses = array();
  23    $payments_status_array = array();
  24    $payments_status_query = tep_db_query("select affiliate_payment_status_id, affiliate_payment_status_name from " . TABLE_AFFILIATE_PAYMENT_STATUS . " where affiliate_language_id = '" . $languages_id . "'");
  25    while ($payments_status = tep_db_fetch_array($payments_status_query)) {
  26      $payments_statuses[] = array('id' => $payments_status['affiliate_payment_status_id'],
  27                                   'text' => $payments_status['affiliate_payment_status_name']);
  28      $payments_status_array[$payments_status['affiliate_payment_status_id']] = $payments_status['affiliate_payment_status_name'];
  29    }
  30  
  31    switch ($HTTP_GET_VARS['action']) {
  32      case 'start_billing':
  33  // Billing can be a lengthy process

  34        tep_set_time_limit(0);
  35  // We are only billing orders which are AFFILIATE_BILLING_TIME days old

  36        $time = mktime(1, 1, 1, date("m"), date("d") - AFFILIATE_BILLING_TIME, date("Y"));
  37        $oldday = date("Y-m-d", $time);
  38  // Select all affiliates who earned enough money since last payment

  39        $sql="
  40          SELECT a.affiliate_id, sum(a.affiliate_payment) 
  41            FROM " . TABLE_AFFILIATE_SALES . " a, " . TABLE_ORDERS . " o 
  42            WHERE a.affiliate_billing_status != 1 and a.affiliate_orders_id = o.orders_id and o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . " and a.affiliate_date <= '" . $oldday . "' 
  43            GROUP by a.affiliate_id 
  44            having sum(a.affiliate_payment) >= '" . AFFILIATE_THRESHOLD . "'
  45          ";
  46        $affiliate_payment_query = tep_db_query($sql);
  47  
  48  // Start Billing:

  49        while ($affiliate_payment = tep_db_fetch_array($affiliate_payment_query)) {
  50  
  51  // mysql does not support joins in update (planned in 4.x)

  52  
  53  // Get all orders which are AFFILIATE_BILLING_TIME days old

  54          $sql="
  55          SELECT a.affiliate_orders_id 
  56            FROM " . TABLE_AFFILIATE_SALES . " a, " . TABLE_ORDERS . " o 
  57            WHERE a.affiliate_billing_status!=1 and a.affiliate_orders_id=o.orders_id and o.orders_status>=" . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . " and a.affiliate_id='" . $affiliate_payment['affiliate_id'] . "' and a.affiliate_date <= '" . $oldday . "'
  58          ";
  59          $affiliate_orders_query=tep_db_query ($sql);
  60          $orders_id ="(";
  61          while ($affiliate_orders = tep_db_fetch_array($affiliate_orders_query)) {
  62            $orders_id .= $affiliate_orders['affiliate_orders_id'] . ",";
  63          }
  64          $orders_id = substr($orders_id, 0, -1) .")";
  65  
  66  // Set the Sales to Temp State (it may happen that an order happend while billing)

  67          $sql="UPDATE " . TABLE_AFFILIATE_SALES . " 
  68          set affiliate_billing_status=99 
  69            where affiliate_id='" .  $affiliate_payment['affiliate_id'] . "' 
  70            and affiliate_orders_id in " . $orders_id . " 
  71          ";
  72          tep_db_query ($sql);
  73  
  74  // Get Sum of payment (Could have changed since last selects);

  75          $sql="
  76          SELECT sum(affiliate_payment) as affiliate_payment
  77            FROM " . TABLE_AFFILIATE_SALES . " 
  78            WHERE affiliate_id='" .  $affiliate_payment['affiliate_id'] . "' and  affiliate_billing_status=99 
  79          ";
  80          $affiliate_billing_query = tep_db_query ($sql);
  81          $affiliate_billing = tep_db_fetch_array($affiliate_billing_query);
  82  // Get affiliate Informations

  83          $sql="
  84          SELECT a.*, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id 
  85            from " . TABLE_AFFILIATE . " a 
  86            left join " . TABLE_ZONES . " z on (a.affiliate_zone_id  = z.zone_id) 
  87            left join " . TABLE_COUNTRIES . " c on (a.affiliate_country_id = c.countries_id)
  88            WHERE affiliate_id = '" . $affiliate_payment['affiliate_id'] . "' 
  89          ";
  90          $affiliate_query=tep_db_query ($sql);
  91          $affiliate = tep_db_fetch_array($affiliate_query);
  92  
  93  // Get need tax informations for the affiliate

  94          $affiliate_tax_rate = tep_get_affiliate_tax_rate(AFFILIATE_TAX_ID, $affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id']);
  95          $affiliate_tax = tep_round(($affiliate_billing['affiliate_payment'] * $affiliate_tax_rate / 100), 2); // Netto-Provision

  96          $affiliate_payment_total = $affiliate_billing['affiliate_payment'] + $affiliate_tax;
  97  // Bill the order

  98          $affiliate['affiliate_state'] = tep_get_zone_code($affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id'], $affiliate['affiliate_state']);
  99          $sql_data_array = array('affiliate_id' => $affiliate_payment['affiliate_id'],
 100                                  'affiliate_payment' => $affiliate_billing['affiliate_payment'],
 101                                  'affiliate_payment_tax' => $affiliate_tax,
 102                                  'affiliate_payment_total' => $affiliate_payment_total,
 103                                  'affiliate_payment_date' => 'now()',
 104                                  'affiliate_payment_status' => '0',
 105                                  'affiliate_firstname' => $affiliate['affiliate_firstname'],
 106                                  'affiliate_lastname' => $affiliate['affiliate_lastname'],
 107                                  'affiliate_street_address' => $affiliate['affiliate_street_address'],
 108                                  'affiliate_suburb' => $affiliate['affiliate_suburb'],
 109                                  'affiliate_city' => $affiliate['affiliate_city'],
 110                                  'affiliate_country' => $affiliate['countries_name'],
 111                                  'affiliate_postcode' => $affiliate['affiliate_postcode'],
 112                                  'affiliate_company' => $affiliate['affiliate_company'],
 113                                  'affiliate_state' => $affiliate['affiliate_state'],
 114                                  'affiliate_address_format_id' => $affiliate['address_format_id']);
 115          tep_db_perform(TABLE_AFFILIATE_PAYMENT, $sql_data_array);
 116          $insert_id = tep_db_insert_id(); 
 117  // Set the Sales to Final State 

 118          tep_db_query("update " . TABLE_AFFILIATE_SALES . " set affiliate_payment_id = '" . $insert_id . "', affiliate_billing_status = 1, affiliate_payment_date = now() where affiliate_id = '" . $affiliate_payment['affiliate_id'] . "' and affiliate_billing_status = 99");
 119  
 120  // Notify Affiliate

 121          if (AFFILIATE_NOTIFY_AFTER_BILLING == 'true') {
 122            $check_status_query = tep_db_query("select af.affiliate_email_address, ap.affiliate_lastname, ap.affiliate_firstname, ap.affiliate_payment_status, ap.affiliate_payment_date, ap.affiliate_payment_date from " . TABLE_AFFILIATE_PAYMENT . " ap, " . TABLE_AFFILIATE . " af where affiliate_payment_id  = '" . $insert_id . "' and af.affiliate_id = ap.affiliate_id ");
 123            $check_status = tep_db_fetch_array($check_status_query);
 124            $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_AFFILIATE_PAYMENT_NUMBER . ' ' . $insert_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_AFFILIATE_PAYMENT_INFO, 'payment_id=' . $insert_id, 'SSL') . "\n" . EMAIL_TEXT_PAYMENT_BILLED . ' ' . tep_date_long($check_status['affiliate_payment_date']) . "\n\n" . EMAIL_TEXT_NEW_PAYMENT;
 125            tep_mail($check_status['affiliate_firstname'] . ' ' . $check_status['affiliate_lastname'], $check_status['affiliate_email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, AFFILIATE_EMAIL_ADDRESS);
 126          }
 127        }
 128        $messageStack->add_session(SUCCESS_BILLING, 'success');
 129  
 130        tep_redirect(tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('action')) . 'action=edit'));
 131        break;
 132      case 'update_payment':
 133        $pID = tep_db_prepare_input($HTTP_GET_VARS['pID']);
 134        $status = tep_db_prepare_input($HTTP_POST_VARS['status']);
 135  
 136        $payment_updated = false;
 137        $check_status_query = tep_db_query("select af.affiliate_email_address, ap.affiliate_lastname, ap.affiliate_firstname, ap.affiliate_payment_status, ap.affiliate_payment_date, ap.affiliate_payment_date from " . TABLE_AFFILIATE_PAYMENT . " ap, " . TABLE_AFFILIATE . " af where affiliate_payment_id = '" . tep_db_input($pID) . "' and af.affiliate_id = ap.affiliate_id ");
 138        $check_status = tep_db_fetch_array($check_status_query);
 139        if ($check_status['affiliate_payment_status'] != $status) {
 140          tep_db_query("update " . TABLE_AFFILIATE_PAYMENT . " set affiliate_payment_status = '" . tep_db_input($status) . "', affiliate_last_modified = now() where affiliate_payment_id = '" . tep_db_input($pID) . "'");
 141          $affiliate_notified = '0';
 142  // Notify Affiliate

 143          if ($HTTP_POST_VARS['notify'] == 'on') {
 144            $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_AFFILIATE_PAYMENT_NUMBER . ' ' . $pID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_AFFILIATE_PAYMENT_INFO, 'payment_id=' . $pID, 'SSL') . "\n" . EMAIL_TEXT_PAYMENT_BILLED . ' ' . tep_date_long($check_status['affiliate_payment_date']) . "\n\n" . sprintf(EMAIL_TEXT_STATUS_UPDATE, $payments_status_array[$status]);
 145            tep_mail($check_status['affiliate_firstname'] . ' ' . $check_status['affiliate_lastname'], $check_status['affiliate_email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, AFFILIATE_EMAIL_ADDRESS);
 146            $affiliate_notified = '1';
 147          }
 148  
 149          tep_db_query("insert into " . TABLE_AFFILIATE_PAYMENT_STATUS_HISTORY . " (affiliate_payment_id, affiliate_new_value, affiliate_old_value, affiliate_date_added, affiliate_notified) values ('" . tep_db_input($pID) . "', '" . tep_db_input($status) . "', '" . $check_status['affiliate_payment_status'] . "', now(), '" . $affiliate_notified . "')");
 150          $order_updated = true;
 151        }
 152  
 153        if ($order_updated) {
 154         $messageStack->add_session(SUCCESS_PAYMENT_UPDATED, 'success');
 155        }
 156  
 157        tep_redirect(tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('action')) . 'action=edit'));
 158        break;
 159      case 'deleteconfirm':
 160        $pID = tep_db_prepare_input($HTTP_GET_VARS['pID']);
 161  
 162        tep_db_query("delete from " . TABLE_AFFILIATE_PAYMENT . " where affiliate_payment_id = '" . tep_db_input($pID) . "'");
 163        tep_db_query("delete from " . TABLE_AFFILIATE_PAYMENT_STATUS_HISTORY . " where affiliate_payment_id = '" . tep_db_input($pID) . "'");
 164  
 165        tep_redirect(tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action'))));
 166        break;
 167    }
 168  
 169    if ( ($HTTP_GET_VARS['action'] == 'edit') && tep_not_null($HTTP_GET_VARS['pID']) ) {
 170      $pID = tep_db_prepare_input($HTTP_GET_VARS['pID']);
 171      $payments_query = tep_db_query("select p.*,  a.affiliate_payment_check, a.affiliate_payment_paypal, a.affiliate_payment_bank_name, a.affiliate_payment_bank_branch_number, a.affiliate_payment_bank_swift_code, a.affiliate_payment_bank_account_name, a.affiliate_payment_bank_account_number from " .  TABLE_AFFILIATE_PAYMENT . " p, " . TABLE_AFFILIATE . " a where affiliate_payment_id = '" . tep_db_input($pID) . "' and a.affiliate_id = p.affiliate_id");
 172      $payments_exists = true;
 173      if (!$payments = tep_db_fetch_array($payments_query)) {
 174        $payments_exists = false;
 175        $messageStack->add(sprintf(ERROR_PAYMENT_DOES_NOT_EXIST, $pID), 'error');
 176      }
 177    }
 178  ?>
 179  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 180  <html <?php echo HTML_PARAMS; ?>>
 181  <head>
 182  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 183  <title><?php echo TITLE; ?></title>
 184  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 185  </head>
 186  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
 187  <!-- header //-->
 188  <?php
 189    require (DIR_WS_INCLUDES . 'header.php');
 190  ?>
 191  <!-- header_eof //-->
 192  
 193  <!-- body //-->
 194  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 195    <tr>
 196      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
 197  <!-- left_navigation //-->
 198  <?php require (DIR_WS_INCLUDES . 'column_left.php'); ?>
 199  <!-- left_navigation_eof //-->
 200      </table></td>
 201  <!-- body_text //-->
 202      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 203  <?php
 204    if ( ($HTTP_GET_VARS['action'] == 'edit') && ($payments_exists) ) {
 205      $affiliate_address['firstname'] = $payments['affiliate_firstname'];
 206      $affiliate_address['lastname'] = $payments['affiliate_lastname'];
 207      $affiliate_address['street_address'] = $payments['affiliate_street_address'];
 208      $affiliate_address['suburb'] = $payments['affiliate_suburb'];
 209      $affiliate_address['city'] = $payments['affiliate_city'];
 210      $affiliate_address['state'] = $payments['affiliate_state'];
 211      $affiliate_address['country'] = $payments['affiliate_country'];
 212      $affiliate_address['postcode'] = $payments['affiliate_postcode'];
 213  ?>
 214        <tr>
 215          <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 216            <tr>
 217              <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
 218              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
 219              <td class="pageHeading" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('action'))) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
 220            </tr>
 221          </table></td>
 222        </tr>
 223        <tr>
 224          <td><table width="100%" border="0" cellspacing="0" cellpadding="2">
 225            <tr>
 226              <td colspan="2"><?php echo tep_draw_separator(); ?></td>
 227            </tr>
 228            <tr>
 229              <td valign="top"><table border="0" cellspacing="0" cellpadding="2">
 230                <tr>
 231                  <td class="main" valign="top"><b><?php echo TEXT_AFFILIATE; ?></b></td>
 232                  <td class="main"><?php echo tep_address_format($payments['affiliate_address_format_id'], $affiliate_address, 1, '&nbsp;', '<br>'); ?></td>
 233                </tr>
 234                <tr>
 235                  <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
 236                </tr>
 237                <tr>
 238                  <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
 239                </tr>
 240                <tr>
 241                  <td class="main"><b><?php echo TEXT_AFFILIATE_PAYMENT; ?></b></td>
 242                  <td class="main">&nbsp;<?php echo $currencies->format($payments['affiliate_payment_total']); ?></td>
 243                </tr>
 244                <tr>
 245                  <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
 246                </tr>
 247                <tr>
 248                  <td class="main"><b><?php echo TEXT_AFFILIATE_BILLED; ?></b></td>
 249                  <td class="main">&nbsp;<?php echo tep_date_short($payments['affiliate_payment_date']); ?></td>
 250                </tr>
 251                <tr>
 252                  <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
 253                </tr>
 254                <tr>
 255                  <td class="main" valign="top"><b><?php echo TEXT_AFFILIATE_PAYING_POSSIBILITIES; ?></b></td>
 256                  <td class="main"><table border="1" cellspacing="0" cellpadding="5">
 257                    <tr>
 258  <?php
 259    if (AFFILIATE_USE_BANK == 'true') {
 260  ?>
 261                      <td class="main"  valign="top"><?php echo '<b>' . TEXT_AFFILIATE_PAYMENT_BANK_TRANSFER . '</b><br><br>' . TEXT_AFFILIATE_PAYMENT_BANK_NAME . ' ' . $payments['affiliate_payment_bank_name'] . '<br>' . TEXT_AFFILIATE_PAYMENT_BANK_BRANCH_NUMBER . ' ' . $payments['affiliate_payment_bank_branch_number'] . '<br>' . TEXT_AFFILIATE_PAYMENT_BANK_SWIFT_CODE . ' ' . $payments['affiliate_payment_bank_swift_code'] . '<br>' . TEXT_AFFILIATE_PAYMENT_BANK_ACCOUNT_NAME . ' ' . $payments['affiliate_payment_bank_account_name'] . '<br>' . TEXT_AFFILIATE_PAYMENT_BANK_ACCOUNT_NUMBER . ' ' . $payments['affiliate_payment_bank_account_number'] . '<br>'; ?></td>
 262  <?php
 263    }
 264    if (AFFILIATE_USE_PAYPAL == 'true') {
 265  ?>
 266                      <td class="main"  valign="top"><?php echo '<b>' . TEXT_AFFILIATE_PAYMENT_PAYPAL . '</b><br><br>' . TEXT_AFFILIATE_PAYMENT_PAYPAL_EMAIL . '<br>' . $payments['affiliate_payment_paypal'] . '<br>'; ?></td>
 267  <?php
 268    }
 269    if (AFFILIATE_USE_CHECK == 'true') {
 270  ?>
 271                      <td class="main"  valign="top"><?php echo '<b>' . TEXT_AFFILIATE_PAYMENT_CHECK . '</b><br><br>' . TEXT_AFFILIATE_PAYMENT_CHECK_PAYEE . '<br>' . $payments['affiliate_payment_check'] . '<br>'; ?></td>
 272  <?php
 273    }
 274  ?>
 275                    </tr>
 276                  </table></td>
 277                </tr>
 278              </table></td>
 279            </tr>
 280          </table></td>
 281        </tr>
 282        <tr>
 283          <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
 284        </tr>
 285        <tr>
 286  <?php echo tep_draw_form('status', FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('action')) . 'action=update_payment'); ?>
 287          <td><table border="0" cellspacing="0" cellpadding="2">
 288            <tr>
 289              <td><table border="0" cellspacing="0" cellpadding="2">
 290                <tr>
 291                  <td class="main"><b><?php echo PAYMENT_STATUS; ?></b> <?php echo tep_draw_pull_down_menu('status', $payments_statuses, $payments['affiliate_payment_status']); ?></td>
 292                </tr>
 293                <tr>
 294                  <td class="main"><b><?php echo PAYMENT_NOTIFY_AFFILIATE; ?></b><?php echo tep_draw_checkbox_field('notify', '', true); ?></td>
 295                </tr>
 296              </table></td>
 297              <td valign="top"><?php echo tep_image_submit('button_update.gif', IMAGE_UPDATE); ?></td>
 298            </tr>
 299          </table></td>
 300        </form></tr>
 301  
 302        <tr>
 303          <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
 304        </tr>
 305        <tr>
 306          <td class="main"><table border="1" cellspacing="0" cellpadding="5">
 307            <tr>
 308              <td class="smallText" align="center"><b><?php echo TABLE_HEADING_NEW_VALUE; ?></b></td>
 309              <td class="smallText" align="center"><b><?php echo TABLE_HEADING_OLD_VALUE; ?></b></td>
 310              <td class="smallText" align="center"><b><?php echo TABLE_HEADING_DATE_ADDED; ?></b></td>
 311              <td class="smallText" align="center"><b><?php echo TABLE_HEADING_AFFILIATE_NOTIFIED; ?></b></td>
 312            </tr>
 313  <?php
 314      $affiliate_history_query = tep_db_query("select affiliate_new_value, affiliate_old_value, affiliate_date_added, affiliate_notified from " . TABLE_AFFILIATE_PAYMENT_STATUS_HISTORY . " where affiliate_payment_id = '" . tep_db_input($pID) . "' order by affiliate_status_history_id desc");
 315      if (tep_db_num_rows($affiliate_history_query)) {
 316        while ($affiliate_history = tep_db_fetch_array($affiliate_history_query)) {
 317          echo '          <tr>' . "\n" .
 318               '            <td class="smallText">' . $payments_status_array[$affiliate_history['affiliate_new_value']] . '</td>' . "\n" .
 319               '            <td class="smallText">' . (tep_not_null($affiliate_history['affiliate_old_value']) ? $payments_status_array[$affiliate_history['affiliate_old_value']] : '&nbsp;') . '</td>' . "\n" .
 320               '            <td class="smallText" align="center">' . tep_date_short($affiliate_history['affiliate_date_added']) . '</td>' . "\n" .
 321               '            <td class="smallText" align="center">';
 322          if ($affiliate_history['affiliate_notified'] == '1') {
 323            echo tep_image(DIR_WS_ICONS . 'tick.gif', ICON_TICK);
 324          } else {
 325            echo tep_image(DIR_WS_ICONS . 'cross.gif', ICON_CROSS);
 326          }
 327          echo '          </tr>' . "\n";
 328        }
 329      } else {
 330          echo '          <tr>' . "\n" .
 331               '            <td class="smallText" colspan="4">' . TEXT_NO_PAYMENT_HISTORY . '</td>' . "\n" .
 332               '          </tr>' . "\n";
 333      }
 334  ?>
 335          </table></td>
 336        </tr>
 337        <tr>
 338          <td colspan="2" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_INVOICE, 'pID=' . $HTTP_GET_VARS['pID']) . '" TARGET="_blank">' . tep_image_button('button_invoice.gif', IMAGE_ORDERS_INVOICE) . '</a> <a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('action'))) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
 339        </tr>
 340  <?php
 341    } else {
 342  ?>
 343        <tr>
 344          <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 345            <tr>
 346              <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
 347              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
 348              <td class="pageHeading"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, 'pID=' . $pInfo->affiliate_payment_id. '&action=start_billing' ) . '">' . tep_image_button('button_affiliate_billing.gif', IMAGE_AFFILIATE_BILLING) . '</a>'; ?></td>
 349              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
 350              <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 351                <tr><?php echo tep_draw_form('orders', FILENAME_AFFILIATE_PAYMENT, '', 'get'); ?>
 352                  <td class="smallText" align="right"><?php echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('sID', '', 'size="12"') . tep_draw_hidden_field('action', 'edit'); ?></td>
 353                </form></tr>
 354                <tr><?php echo tep_draw_form('status', FILENAME_AFFILIATE_PAYMENT, '', 'get'); ?>
 355                  <td class="smallText" align="right"><?php echo HEADING_TITLE_STATUS . ' ' . tep_draw_pull_down_menu('status', array_merge(array(array('id' => '', 'text' => TEXT_ALL_PAYMENTS)), $payments_statuses), '', 'onChange="this.form.submit();"'); ?></td>
 356                </form></tr>
 357              </table></td>
 358            </tr>
 359          </table></td>
 360        </tr>
 361        <tr>
 362          <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
 363            <tr>
 364              <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 365                <tr class="dataTableHeadingRow">
 366                  <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_AFILIATE_NAME; ?></td>
 367                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_NET_PAYMENT; ?></td>
 368                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PAYMENT; ?></td>
 369                  <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DATE_BILLED; ?></td>
 370                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?></td>
 371                  <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
 372                </tr>
 373  <?php
 374      if ($HTTP_GET_VARS['sID']) {
 375        // Search only payment_id by now

 376        $sID = tep_db_prepare_input($HTTP_GET_VARS['sID']);
 377        $payments_query_raw = "select p.* , s.affiliate_payment_status_name from " . TABLE_AFFILIATE_PAYMENT . " p , " . TABLE_AFFILIATE_PAYMENT_STATUS . " s where p.affiliate_payment_id = '" . tep_db_input($sID) . "' and p.affiliate_payment_status = s.affiliate_payment_status_id and s.affiliate_language_id = '" . $languages_id . "' order by p.affiliate_payment_id DESC";
 378      } elseif (is_numeric($HTTP_GET_VARS['status'])) {
 379        $status = tep_db_prepare_input($HTTP_GET_VARS['status']);
 380        $payments_query_raw = "select p.* , s.affiliate_payment_status_name from " . TABLE_AFFILIATE_PAYMENT . " p , " . TABLE_AFFILIATE_PAYMENT_STATUS . " s where s.affiliate_payment_status_id = '" . tep_db_input($status) . "' and p.affiliate_payment_status = s.affiliate_payment_status_id and s.affiliate_language_id = '" . $languages_id . "' order by p.affiliate_payment_id DESC";
 381      } else {
 382        $payments_query_raw = "select p.* , s.affiliate_payment_status_name from " . TABLE_AFFILIATE_PAYMENT . " p , " . TABLE_AFFILIATE_PAYMENT_STATUS . " s where p.affiliate_payment_status = s.affiliate_payment_status_id and s.affiliate_language_id = '" . $languages_id . "' order by p.affiliate_payment_id DESC";
 383      }
 384      $payments_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $payments_query_raw, $payments_query_numrows);
 385      $payments_query = tep_db_query($payments_query_raw);
 386      while ($payments = tep_db_fetch_array($payments_query)) {
 387        if (((!$HTTP_GET_VARS['pID']) || ($HTTP_GET_VARS['pID'] == $payments['affiliate_payment_id'])) && (!$pInfo)) {
 388          $pInfo = new objectInfo($payments);
 389        }
 390  
 391        if ( (is_object($pInfo)) && ($payments['affiliate_payment_id'] == $pInfo->affiliate_payment_id) ) {
 392          echo '              <tr class="dataTableRowSelected" onmouseover="this.style.cursor=\'hand\'" onclick="document.location.href=\'' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $pInfo->affiliate_payment_id . '&action=edit') . '\'">' . "\n";
 393        } else {
 394          echo '              <tr class="dataTableRow" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'hand\'" onmouseout="this.className=\'dataTableRow\'" onclick="document.location.href=\'' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID')) . 'pID=' . $payments['affiliate_payment_id']) . '\'">' . "\n";
 395        }
 396  ?>
 397                  <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $pInfo->affiliate_payment_id . '&action=edit') . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;' . $payments['affiliate_firstname'] . ' ' . $payments['affiliate_lastname']; ?></td>
 398                  <td class="dataTableContent" align="right"><?php echo $currencies->format(strip_tags($payments['affiliate_payment'])); ?></td>
 399                  <td class="dataTableContent" align="right"><?php echo $currencies->format(strip_tags($payments['affiliate_payment'] + $payments['affiliate_payment_tax'])); ?></td>
 400                  <td class="dataTableContent" align="center"><?php echo tep_date_short($payments['affiliate_payment_date']); ?></td>
 401                  <td class="dataTableContent" align="right"><?php echo $payments['affiliate_payment_status_name']; ?></td>
 402                  <td class="dataTableContent" align="right"><?php if ( (is_object($pInfo)) && ( $payments['affiliate_payment_id'] == $pInfo->affiliate_payment_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID')) . 'pID=' . $payments['affiliate_payment_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
 403                </tr>
 404  <?php
 405      }
 406  ?>
 407                <tr>
 408                  <td colspan="6"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 409                    <tr>
 410                      <td class="smallText" valign="top"><?php echo $payments_split->display_count($payments_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PAYMENTS); ?></td>
 411                      <td class="smallText" align="right"><?php echo $payments_split->display_links($payments_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], tep_get_all_get_params(array('page', 'pID', 'action'))); ?></td>
 412                    </tr>
 413                  </table></td>
 414                </tr>
 415              </table></td>
 416  <?php
 417    $heading = array();
 418    $contents = array();
 419    switch ($HTTP_GET_VARS['action']) {
 420      case 'delete':
 421        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_PAYMENT . '</b>');
 422  
 423        $contents = array('form' => tep_draw_form('payment', FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $pInfo->affiliate_payment_id. '&action=deleteconfirm'));
 424        $contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br>');
 425        $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $pInfo->affiliate_payment_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
 426        break;
 427      default:
 428        if (is_object($pInfo)) {
 429          $heading[] = array('text' => '<b>[' . $pInfo->affiliate_payment_id . ']&nbsp;&nbsp;' . tep_datetime_short($pInfo->affiliate_payment_date) . '</b>');
 430  
 431          $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $pInfo->affiliate_payment_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_AFFILIATE_PAYMENT, tep_get_all_get_params(array('pID', 'action')) . 'pID=' . $pInfo->affiliate_payment_id  . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');
 432          $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_AFFILIATE_INVOICE, 'pID=' . $pInfo->affiliate_payment_id ) . '" TARGET="_blank">' . tep_image_button('button_invoice.gif', IMAGE_ORDERS_INVOICE) . '</a> ');
 433        }
 434        break;
 435    }
 436  
 437    if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
 438      echo '            <td  width="25%" valign="top">' . "\n";
 439  
 440      $box = new box;
 441      echo $box->infoBox($heading, $contents);
 442  
 443      echo '            </td>' . "\n";
 444    }
 445  ?>
 446            </tr>
 447          </table></td>
 448        </tr>
 449  <?php
 450    }
 451  ?>
 452      </table></td>
 453  <!-- body_text_eof //-->
 454    </tr>
 455  </table>
 456  <!-- body_eof //-->
 457  
 458  <!-- footer //-->
 459  <?php
 460      require (DIR_WS_INCLUDES . 'footer.php');
 461  ?>
 462  <!-- footer_eof //-->
 463  <br>
 464  </body>
 465  </html>
 466  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>


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