Voici une proposition développée à partir de la ms2fr de monsieur Delaballe. C'est très certainement perfectible, donc ne m'en voulez pas.
Les numéros de lignes indiquées sur les numéros pris sur une version vierge de toutes contributions.
Pour rappel, avant d'installation une contribution d'un(e) inconnu(e), on sauvegarde. Pour ici, il faut sauvegarder ses pages de scripts et sa base de données.
- il s'agit d'une contribution débrayable par l'admin, c'est à dire que si vous ne voulez plus l'utiliser, vous retrouver le mode de fonctionnement standard de votre boutique.
- il s'agit d'attribuer un numéro de facture unique à chaque vente réputée définitive, telle que l'avait voulu la personne qui a demandé ce développement.
- le numéro de facture est un compteur numérique séquentiel : 1, 2, 3, 4, 5, ...
- un numéro de facture est attribué quand une commande atteint un certain état. Par défaut, ici, le statut "Livré", correspondant à l'id 3, déclenche un numéro de facture. Le numéro de l'état déclenchant est modifiable par la console d'aministration. Si par exemple, un vendeur souhaite attribuer un numéro de facture quand une commande est à l'état "En cours de traitement", il codera l'id 2.
- aucun support par MP pour ces bouts de code : si nécessaire les réponses seront apportées dans le forum pour que tout le monde en profite.
CODE
CREATE TABLE `invoice_counter` (
`invoice_id` int(11) NOT NULL default '0',
`invoice_counter` int(11) NOT NULL default '0',
KEY `invoice_id` (`invoice_id`)
) TYPE=MyISAM;
#
# Contenu de la table `invoice_counter`
#
INSERT INTO `invoice_counter` VALUES (1, 1);
`invoice_id` int(11) NOT NULL default '0',
`invoice_counter` int(11) NOT NULL default '0',
KEY `invoice_id` (`invoice_id`)
) TYPE=MyISAM;
#
# Contenu de la table `invoice_counter`
#
INSERT INTO `invoice_counter` VALUES (1, 1);
CODE
INSERT INTO `configuration_group` VALUES (421, 'Options Facture', 'Options pour les factures', 421, 1);
INSERT INTO `configuration` VALUES ('', 'Calcul d un numéro de facture différent du numéro de commande', 'AUTORISE_NUMERO_FACTURE', 'true', 'Calcule un numéro de facture à chaque vente effective', 421, 2, '2004-06-20 18:16:28', '2003-07-17 10:29:22', NULL, 'tep_cfg_select_option(array(\'true\', \'false\'),');
INSERT INTO `configuration` VALUES ('', 'Statut générant une facture', 'STATUT_GENERANT_FACTURE', '3', 'Statut d une commande permettant l attribution d un numéro de facture unique', 421, 1, '2004-06-12 22:53:27', '2003-07-17 10:29:22', NULL, NULL);
INSERT INTO `configuration` VALUES ('', 'Calcul d un numéro de facture différent du numéro de commande', 'AUTORISE_NUMERO_FACTURE', 'true', 'Calcule un numéro de facture à chaque vente effective', 421, 2, '2004-06-20 18:16:28', '2003-07-17 10:29:22', NULL, 'tep_cfg_select_option(array(\'true\', \'false\'),');
INSERT INTO `configuration` VALUES ('', 'Statut générant une facture', 'STATUT_GENERANT_FACTURE', '3', 'Statut d une commande permettant l attribution d un numéro de facture unique', 421, 1, '2004-06-12 22:53:27', '2003-07-17 10:29:22', NULL, NULL);
CODE
ALTER TABLE `orders` ADD `orders_numero_facture` INT( 11 ) NOT NULL;
En ligne 27, remplacer :
CODE
$order_query = tep_db_query("select customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
par
CODE
$order_query = tep_db_query("select customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified, orders_numero_facture from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
En ligne 45, remplacer :
CODE
'last_modified' => $order['last_modified']);
par
CODE
'last_modified' => $order['last_modified'],
'orders_numero_facture' => $order['orders_numero_facture']);
'orders_numero_facture' => $order['orders_numero_facture']);
En ligne 19, remplacer :
CODE
$orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
par
CODE
$orders_query = tep_db_query("select orders_id, orders_numero_facture from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
En ligne 35, remplacer :
CODE
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo nl2br(STORE_NAME_ADDRESS); ?></td>
<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce', '204', '50'); ?></td>
</tr>
</table></td>
</tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo nl2br(STORE_NAME_ADDRESS); ?></td>
<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce', '204', '50'); ?></td>
</tr>
</table></td>
</tr>
par
CODE
<tr>
<td><table border="0" align="center" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><table border="0" align="center" width="75%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo nl2br(STORE_NAME_ADDRESS); ?></td>
<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce', '204', '50'); ?></td>
</tr>
<tr align="left">
<td colspan="2" class="titleHeading"><?php echo tep_draw_separator('pixel_trans.gif', '1', '30'); ?></td>
</tr>
<tr>
<?php
if (AUTORISE_NUMERO_FACTURE == 'true') {
if ($order->info['orders_numero_facture'] == 0) {
?>
<td colspan="2" align="center" class="titleHeading"><b><?php echo TITLE_PRINT_ORDER . $oID; ?></b></td>
<?php
} else {
?>
<td colspan="2" align="center" class="titleHeading"><b><?php echo TITLE_PRINT_INVOICE . $order->info['orders_numero_facture']; ?></b></td>
<?php
}
} else {
?>
<td colspan="2" align="center" class="titleHeading"><b><?php echo TITLE_PRINT_ORDER . $oID; ?></b></td>
<?php
}
?>
</tr>
<tr align="left">
<td colspan="2" class="titleHeading"><?php echo tep_draw_separator('pixel_trans.gif', '1', '30'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<td><table border="0" align="center" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><table border="0" align="center" width="75%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo nl2br(STORE_NAME_ADDRESS); ?></td>
<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce', '204', '50'); ?></td>
</tr>
<tr align="left">
<td colspan="2" class="titleHeading"><?php echo tep_draw_separator('pixel_trans.gif', '1', '30'); ?></td>
</tr>
<tr>
<?php
if (AUTORISE_NUMERO_FACTURE == 'true') {
if ($order->info['orders_numero_facture'] == 0) {
?>
<td colspan="2" align="center" class="titleHeading"><b><?php echo TITLE_PRINT_ORDER . $oID; ?></b></td>
<?php
} else {
?>
<td colspan="2" align="center" class="titleHeading"><b><?php echo TITLE_PRINT_INVOICE . $order->info['orders_numero_facture']; ?></b></td>
<?php
}
} else {
?>
<td colspan="2" align="center" class="titleHeading"><b><?php echo TITLE_PRINT_ORDER . $oID; ?></b></td>
<?php
}
?>
</tr>
<tr align="left">
<td colspan="2" class="titleHeading"><?php echo tep_draw_separator('pixel_trans.gif', '1', '30'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
En ligne 37, remplacer :
CODE
$check_status_query = tep_db_query("select customers_name, customers_email_address, orders_status, date_purchased from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
Par
CODE
$check_status_query = tep_db_query("select customers_name, customers_email_address, orders_status, date_purchased, orders_numero_facture from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
En ligne 41, remplacer :
CODE
tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . tep_db_input($status) . "', last_modified = now() where orders_id = '" . (int)$oID . "'");
Par
CODE
tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . tep_db_input($status) . "', last_modified = now() where orders_id = '" . (int)$oID . "'");
if (AUTORISE_NUMERO_FACTURE == 'true') {
if (tep_db_input($status) == STATUT_GENERANT_FACTURE) {
$check_invoice_counter_query = tep_db_query("select invoice_counter from " . TABLE_INVOICE_COUNTER . " where invoice_id = '1'");
$check_invoice_counter = tep_db_fetch_array($check_invoice_counter_query);
$numero_facture = $check_invoice_counter['invoice_counter'] + 1;
if ($check_status['orders_numero_facture'] == 0) {
tep_db_query("update " . TABLE_INVOICE_COUNTER . " set invoice_counter = '" . $numero_facture . "' where invoice_id = '1'");
tep_db_query("update " . TABLE_ORDERS . " set orders_numero_facture = '" . $numero_facture . "', last_modified = now() where orders_id = '" . (int)$oID . "'");
} else {
$messageStack->add_session(WARNING_ORDER_WITH_NUMERO, 'warning');
}
}
}
if (AUTORISE_NUMERO_FACTURE == 'true') {
if (tep_db_input($status) == STATUT_GENERANT_FACTURE) {
$check_invoice_counter_query = tep_db_query("select invoice_counter from " . TABLE_INVOICE_COUNTER . " where invoice_id = '1'");
$check_invoice_counter = tep_db_fetch_array($check_invoice_counter_query);
$numero_facture = $check_invoice_counter['invoice_counter'] + 1;
if ($check_status['orders_numero_facture'] == 0) {
tep_db_query("update " . TABLE_INVOICE_COUNTER . " set invoice_counter = '" . $numero_facture . "' where invoice_id = '1'");
tep_db_query("update " . TABLE_ORDERS . " set orders_numero_facture = '" . $numero_facture . "', last_modified = now() where orders_id = '" . (int)$oID . "'");
} else {
$messageStack->add_session(WARNING_ORDER_WITH_NUMERO, 'warning');
}
}
}
CODE
define('WARNING_ORDER_WITH_NUMERO', 'Attention : Un nouveau numéro de facture n\'a pas été généré, car la commande avait déjà fait l\'objet d\'une facture.');
CODE
define('TABLE_INVOICE_COUNTER', 'invoice_counter');
CODE
define('TITLE_PRINT_ORDER', 'Commande N° ');
define('TITLE_PRINT_INVOICE', 'Facture N° ');
define('TITLE_PRINT_INVOICE', 'Facture N° ');
J'espère que cela pourra servir à quelqu'un, chez moi, cela a l'air de marcher.
