 ------------------------------------------------------
| Order Credit Note - Facture d'Avoir (by Brouillard)  |
 ------------------------------------------------------

Auteur: Brouillard s'embrouille
Version osC : MS 2.2

Note:
- Cette contribution fonctionne en parallèle avec la contrib (Professional Invoice and Packing Slip)
- Vous pouvez rajouter un statut pour la facture d'Avoir (ex : Remboursée, Avoir, Remboursement en cours, Tant pis pour toi !, ...)

Description:

Cette contribution permet de créer une facture d'Avoir pour les commandes retournées (défaut de fabrication, ne convient pas...) et permet aussi de traiter la facture d'Avoir pour ajouter d'autres produits en cas de demande de remplacement (Trop grand, trop p'tit, je veux l'autre réf, ...), tout se fait par l'Admin en un clic.


=====================================================================================================

 -----------------
| MODIFICATON SQL |
 -----------------

ALTER TABLE orders
ADD orders_avoir_id int(11) default NULL

-------------------------------------------------------------------------------------------------------

 ------------------------------
| AJOUTER DES FICHIERS PHP |
 ------------------------------

COPIER LES FICHIERS SUIVANT DANS LEURS DOSSIERS RESPECTIFS:
/admin/invoice_avoir.php
/admin/orders_avoir.php
/admin/images/poubelle.gif

/admin/includes/classes/order_avoir.php
/admin/includes/languages/french/invoice_avoir.php
/admin/includes/languages/french/orders_avoir.php
/admin/includes/languages/french/images/buttons/button_invoice_avoir.gif

-------------------------------------------------------------------------------------------------------

 ------------------------------
| MODIFICATON DES FICHIERS PHP |
 ------------------------------

(1) /admin/includes/classes/shopping_cart.php

* TROUVER:

  function show_total() {


* REMPLACER PAR:

//fonction pour recuperer les options du produits
    function get_attributes($products_id) {
      global $languages_id;

      if (!is_array($this->contents[$products_id]['attributes'])) return 0;
      $attributes_array = array();

      if (isset($this->contents[$products_id]['attributes'])) {
        reset($this->contents[$products_id]['attributes']);
        while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
          $attribute_query = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int)$products_id . "' and pa.options_id = '" . (int)$option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int)$value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int)$languages_id . "' and poval.language_id = '" . (int)$languages_id . "'");

          $attributes_values = tep_db_fetch_array($attribute_query);

          $attributes_array[] = array('products_options' => $attributes_values['products_options_name'],
                                      'products_options_values' => $attributes_values['products_options_values_name'], 
                                      'options_values_price' => $attributes_values['options_values_price'], 
                                      'price_prefix' => $attributes_values['price_prefix']);
        }
      }

      return $attributes_array;
    }
//Fin

    function show_total() {


(2) /admin/orders.php

(2-1)
* TROUVER:

      o.customers_name, o.payment_method

* REMPLACER PAR:

     o.customers_name, o.customers_id, o.payment_method


(2-2)
* TROUVER:

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
?>

* REMPLACER PAR:

//################### FACTURE D'AVOIR ##############################
   $orders_avoir = tep_db_query("select orders_avoir_id from " . TABLE_ORDERS . " where orders_id = '" . $oInfo->orders_id . "'"); $orders_avoir_id = tep_db_fetch_array($orders_avoir);

    echo '            <td width="25%" valign="top">
                      <table border="0" summary="" width="100%" cellspacing="0" cellpadding="2">' . "\n";

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) && $orders_avoir_id['orders_avoir_id'] == '' ) {
    echo '            <tr>
                      <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td></tr>' . "\n";
  }
?>

<?php
  $heading = array();
  $contents = array();

  switch ($action) {
    case 'delete':
        if ($orders_avoir_id['orders_avoir_id'] != '') {
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_ORDER . '</b>');

      $contents = array('form' => tep_draw_form('orders', FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br><br><b>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</b>');
      $contents[] = array('text' => '<br>' . tep_draw_checkbox_field('restock') . ' ' . TEXT_INFO_RESTOCK_PRODUCT_QUANTITY);
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
     }
      break;
    default:
      if (isset($oInfo) && is_object($oInfo)) {
        $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_CREDIT_NOTE . '[' . $orders_avoir_id['orders_avoir_id'] . ']&nbsp;&nbsp;</b>');

        if ($orders_avoir_id['orders_avoir_id'] == '') {
        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_ORDERS_AVOIR, 'oID=' . $oInfo->orders_id . '&action=add_order') . '">' . tep_image_button('button_insert.gif', IMAGE_INSERT) . '</a>');
       }

        if ($orders_avoir_id['orders_avoir_id'] != '') {
        $contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=delete') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');

        $contents[] = array( 'align' => 'center', 'text' => '</a> <a href="' .  tep_href_link(FILENAME_ORDERS_AVOIR, 'oID=' . $oInfo->orders_id . '&action=edit_order') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a>  <a href="' . tep_href_link(FILENAME_ORDERS_INVOICE_AVOIR, 'oID=' . $oInfo->orders_id) . '" TARGET="_blank">' . tep_image_button('button_invoice_avoir.gif', IMAGE_ORDERS_INVOICE_AVOIR));
        }

        $contents[] = array('text' => '<br>' . TEXT_DATE_ORDER_CREATED . ' ' . tep_date_short($oInfo->date_purchased));
        if (tep_not_null($oInfo->last_modified)) $contents[] = array('text' => TEXT_DATE_ORDER_LAST_MODIFIED . ' ' . tep_date_short($oInfo->last_modified));
        $contents[] = array('text' => '<br>' . TEXT_INFO_PAYMENT_METHOD . ' '  . $oInfo->payment_method);
        $contents[] = array('text' => '<br>' . TEXT_CUSTOMERS_ID . ' '  . $oInfo->customers_id);
      }
      break;
  }

  if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
    echo '            <tr>
                      <td width="25%" valign="top">' . "\n";

    $box_avoir = new box;
    echo $box_avoir->infoBox($heading, $contents);

    echo '            </td></tr>' . "\n";
  }

    echo '            </table></td>' . "\n";
//################### FIN FACTURE D'AVOIR ##############################
?>


(3) /admin/includes/filenames.php

* TROUVER LE DERNIER (A LA FIN DU FICHIER):

  ?>


* REMPLACER PAR:

// ################# Contribution Facture d'avoir #################
  define('FILENAME_ORDER_AVOIR', 'order_avoir.php');
  define('FILENAME_ORDERS_AVOIR', 'orders_avoir.php');
  define('FILENAME_ORDERS_INVOICE_AVOIR', 'invoice_avoir.php');
// ################# Fin Contribution Facture d'avoir #################
?>


(4) /admin/includes/languages/french/orders.php

* TROUVER LE DERNIER (A LA FIN DU FICHIER):

  ?>


* REMPLACER PAR:

//################### FACTURE D'AVOIR ##############################
define('TEXT_INFO_HEADING_CREDIT_NOTE', 'TRAITEMENT DE L\'AVOIR DE LA COMMANDE: ');
define('TEXT_CUSTOMERS_ID', 'Identifiant du client: ');
//################### FIN FACTURE D'AVOIR ##############################
?>


(BETWEEN 4 AND 5) /admin/customers

Cette étape n'est pas obligatoire, elle permet de voir l'identifiant du client qui correspond avec le Code client sur la plateforme ATOS.

* TROUVER:

$heading[] = array('text' => '<b>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</b>');

* REMPLACER PAR:

$heading[] = array('text' => '<b>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . ' [' . $cInfo->customers_id . ']</b>');



(5) /catalog/account_history_info.php
(5-1)
* TROUVER:

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));
  $breadcrumb->add(sprintf(NAVBAR_TITLE_3, $HTTP_GET_VARS['order_id']), tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));

* REMPLACER PAR:

//pour avoir un même numéro de commande (avoir et doit)
    $orders_id_query = tep_db_query("select orders_id, orders_avoir_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$customer_id . "' and orders_id = '". (int)($HTTP_GET_VARS['order_id']) ."'");
    while ($orders = tep_db_fetch_array($orders_id_query)) {
      if (tep_not_null($orders['orders_avoir_id'])) {
        $order_id = $orders['orders_avoir_id'];
      } else {
        $order_id = $orders['orders_id'];
      }
     }

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'));
  $breadcrumb->add(sprintf(NAVBAR_TITLE_3, $order_id), tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $HTTP_GET_VARS['order_id'], 'SSL'));

(5-2)
* TROUVER:

            <td class="main" colspan="2"><b><?php echo sprintf(HEADING_ORDER_NUMBER, $HTTP_GET_VARS['order_id']) . ' <small>(' . $order->info['orders_status'] . ')</small>'; ?></b></td>

* REMPLACER PAR:

            <td class="main" colspan="2"><b><?php echo sprintf(HEADING_ORDER_NUMBER, $order_id) . ' <small>(' . $order->info['orders_status'] . ')</small>'; ?></b></td>


(6) /catalog/account_history.php
(6-1)
* TROUVER:

<?php
  $orders_total = tep_count_customer_orders();

  if ($orders_total > 0) {
    $history_query_raw = "select o.orders_id, o.date_purchased, o.delivery_name, o.billing_name, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id DESC";
    $history_split = new splitPageResults($history_query_raw, MAX_DISPLAY_ORDER_HISTORY);
    $history_query = tep_db_query($history_split->sql_query);

    while ($history = tep_db_fetch_array($history_query)) {
      $products_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$history['orders_id'] . "'");
      $products = tep_db_fetch_array($products_query);

      if (tep_not_null($history['delivery_name'])) {
        $order_type = TEXT_ORDER_SHIPPED_TO;
        $order_name = $history['delivery_name'];
      } else {
        $order_type = TEXT_ORDER_BILLED_TO;
        $order_name = $history['billing_name'];
      }
?>

* REMPLACER PAR:

<?php
  $orders_total = tep_count_customer_orders();

  if ($orders_total > 0) {
    $history_query_raw = "select o.orders_avoir_id, o.orders_id, o.date_purchased, o.delivery_name, o.billing_name, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id DESC";
    $history_split = new splitPageResults($history_query_raw, MAX_DISPLAY_ORDER_HISTORY);
    $history_query = tep_db_query($history_split->sql_query);

    while ($history = tep_db_fetch_array($history_query)) {
      $products_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$history['orders_id'] . "'");
      $products = tep_db_fetch_array($products_query);

      if (tep_not_null($history['delivery_name'])) {
        $order_type = TEXT_ORDER_SHIPPED_TO;
        $order_name = $history['delivery_name'];
      } else {
        $order_type = TEXT_ORDER_BILLED_TO;
        $order_name = $history['billing_name'];
      }

      if (tep_not_null($history['orders_avoir_id'])) {
        $order_id = $history['orders_avoir_id'];
      } else {
        $order_id = $history['orders_id'];
      }
?>

(6-2)
* TROUVER:

              <td class="main"><?php echo '<b>' . TEXT_ORDER_NUMBER . '</b> ' . $history['orders_id']; ?></td>


* REMPLACER PAR:

              <td class="main"><?php echo '<b>' . TEXT_ORDER_NUMBER . '</b> ' . $order_id; ?></td>


(7) /catalog/account.php
(7-1)
* TROUVER:

<?php
    $orders_query = tep_db_query("select o.orders_id, o.date_purchased, o.delivery_name, o.delivery_country, o.billing_name, o.billing_country, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id desc limit 3");
    while ($orders = tep_db_fetch_array($orders_query)) {
      if (tep_not_null($orders['delivery_name'])) {
        $order_name = $orders['delivery_name'];
        $order_country = $orders['delivery_country'];
      } else {
        $order_name = $orders['billing_name'];
        $order_country = $orders['billing_country'];
      }
?>

* REMPLACER PAR:

<?php
    $orders_query = tep_db_query("select o.orders_avoir_id, o.orders_id, o.date_purchased, o.delivery_name, o.delivery_country, o.billing_name, o.billing_country, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id desc limit 3");
    while ($orders = tep_db_fetch_array($orders_query)) {
      if (tep_not_null($orders['delivery_name'])) {
        $order_name = $orders['delivery_name'];
        $order_country = $orders['delivery_country'];
      } else {
        $order_name = $orders['billing_name'];
        $order_country = $orders['billing_country'];
      }

      if (tep_not_null($orders['orders_avoir_id'])) {
        $order_id = $orders['orders_avoir_id'];
      } else {
        $order_id = $orders['orders_id'];
      }

?>

(7-2)
* TROUVER:

                    <td class="main"><?php echo '#' . $orders['orders_id']; ?></td>


* REMPLACER PAR:

                    <td class="main"><?php echo '#' . $order_id; ?></td>

