Citation (milie000 @ 24 Feb 2011, 12:10)

J 'ai bien compris qu'avec Ciel cela était impossible.
Ah bon???
Ciel permet l'import de cvs ou de fichier txt... Il suffit donc de faire un petit script pour exporter tes commandes et ça roule!!! J'ai bricolé ça et ça fonctionne bien! Voilà le script si tu veux, mais ce sera plus pour que tu vois le principe, c'est beaucoup trop personnalisé à nos besoins spécifiques pour être utilisé de façon universelle par plug and play.
Code
<?php
/*
$Id: export_ciel.php v1.0 2009/07/19
osCommerce, Open Source E-Commerce Solutions
[url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]
Copyright © 2004 osCommerce
Released under the GNU General Public License
*/
require('includes/application_top.php');
include(DIR_WS_CLASSES . 'order.php');
$dossier = DIR_FS_ADMIN . '/export_ciel/';
$file = 'export_ciel.txt';
$raw_date =0;
function virgule($montant){
$montant = number_format($montant, 2, ',', '');
return $montant;
}
function echeance($raw_date, $echeance) {
if ($raw_date == '') return false;
$year = substr($raw_date, 6, 4);
$month = (int)substr($raw_date, 3, 2);
$day = (int)substr($raw_date, 0, 2) + $echeance;
return date(DATE_FORMAT, mktime(0, 0, 0, $month, $day, $year));
}
if ($_GET['action']) {
switch ($_GET['action']) {
case 'create_file':
$from = tep_db_prepare_input($_POST['from']);
$to = tep_db_prepare_input($_POST['to']);
$orders_query = tep_db_query("SELECT orders_id from " . TABLE_ORDERS . " WHERE orders_id >= '" . $from . "' AND orders_id <= '" . $to . "' order by orders_id");
while($orders = tep_db_fetch_array($orders_query)) {
$order = new order($orders['orders_id']);
$TVA_true = 0;
$debit = 0;
$credit = 0;
$error = 0;
$libelle_sup = '';
// Méthode de paiement
switch (substr($order->info['payment_method'], 0, 3)){
case 'Car':
$payment_method = 'cbl';
break;
case 'Chè':
$payment_method = 'ch';
break;
case 'Esp':
$payment_method = 'es';
break;
case 'Vir':
$payment_method = 'vir';
break;
case '3x ':
$payment_method = '3x';
break;
default :
$payment_method = '';
break;
}
// date
$date = tep_date_short($order->info['date_purchased']);
// Total
$totalTTC_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "' and class='ot_total'");
$totalTTC = tep_db_fetch_array($totalTTC_query);
$totalTTC = $totalTTC['value'];
$totalTVA_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "' and class='ot_tax'");
$totalTVA = tep_db_fetch_array($totalTVA_query);
$totalTVA = $totalTVA['value'];
if ($totalTVA!=0 || $totalTTC!=0) {
// CREDIT articles
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
if (!$order->products[$i]['final_price'] || $order->products[$i]['final_price'] == 0) continue;
// compte
switch ($order->products[$i]['tax']){
case '19.6000':
$compte = '7070000';
break;
case '5.5000':
$compte = '7070015';
break;
default :
$compte = '7079000';
break;
}
if (strtolower(substr($order->products[$i]['name'], 0, 8)) == 'location') $compte = '7083000';
$libelle_sup = '';
if ($order->products[$i]['model'] == 'chqCado') {
$compte = '4191000';
$libelle_sup = '-ca';
}
// Analytique
switch ($order->customer['id']){
case '1':
$analytique = 'LOO';
break;
case '3':
$analytique = 'MAG';
break;
default :
$analytique = 'SITJ';
break;
}
if ($order->products[$i]['name'] == 'Jeu de Go TEACHER') $analytique = 'GO';
if ($order->products[$i]['model'] == 'chqCado') $analytique = "";
// Montant
$price_brut = $order->products[$i]['final_price'] * $order->products[$i]['qty'];
$price = virgule($price_brut);
$credit += tep_round($price_brut, 2);
$ciel_list .= "VT" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= $compte . "\t"; // N° compte
$ciel_list .= "" . "\t"; // débit (total) laisser vide
$ciel_list .= $price . "\t"; // crédit (détail)
$ciel_list .= $orders['orders_id'] . $libelle_sup . "\t"; // libellé
$ciel_list .= "" . "\t"; // Echéancce laisser vide
$ciel_list .= $analytique . "\t"; // code analytique
$ciel_list .= "" . "\t"; // mode de paiement laisser vide
$ciel_list .= chr(13); // \n chr(13) en CRLF
// TVA
if ($order->products[$i]['tax'] != 0){
$TVA_true = 1;
$TVA_brut = tep_round($price_brut * $order->products[$i]['tax']/100, 2);
$TVA = virgule($TVA_brut);
$credit += tep_round($TVA_brut, 2);
// compte
switch ($order->products[$i]['tax']){
case '19.6000':
$compte = '4457130';
break;
case '5.5000':
$compte = '4457100';
break;
}
$ciel_list .= "VT" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= $compte . "\t"; // N° compte
$ciel_list .= "" . "\t"; // débit (total) laisser vide
$ciel_list .= $TVA . "\t"; // crédit (détail)
$ciel_list .= $orders['orders_id'] . "\t"; // libellé
$ciel_list .= "" . "\t"; // Echéancce laisser vide
$ciel_list .= "" . "\t"; // code analytique laisser vide
$ciel_list .= "" . "\t"; // mode de paiement laisser vide
$ciel_list .= chr(13); // \n chr(13) en CRLF
}
} // end for sizeof products
// SHIPPING
$shippingTTC_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "' and class='ot_shipping'");
$shippingTTC = tep_db_fetch_array($shippingTTC_query);
$shippingTTC = tep_round($shippingTTC['value'],2);
$credit += $shippingTTC;
if ($shippingTTC && $shippingTTC!='0'){
// compte shipping
if ($TVA_true){
$compte = '7085000';
$shipping = tep_round($shippingTTC/1.196, 2);
$shipping_ok = virgule($shipping);
$TVA_shipping = virgule($shippingTTC - $shipping);
} else {
$compte = '7089000';
$shipping_ok = virgule($shippingTTC);
}
$ciel_list .= "VT" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= $compte . "\t"; // N° compte
$ciel_list .= "" . "\t"; // débit (total) laisser vide
$ciel_list .= $shipping_ok . "\t"; // crédit (détail)
$ciel_list .= $orders['orders_id'] . "\t"; // libellé
$ciel_list .= "" . "\t"; // Echéancce laisser vide
$ciel_list .= "" . "\t"; // code analytique laisser vide
$ciel_list .= '' . "\t"; // mode de paiement laisser vide
$ciel_list .= chr(13); // \n chr(13) en CRLF
// TVA shipping
if ($TVA_true){
$ciel_list .= "VT" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= '4457130' . "\t"; // N° compte
$ciel_list .= "" . "\t"; // débit (total) laisser vide
$ciel_list .= $TVA_shipping . "\t"; // crédit (détail)
$ciel_list .= $orders['orders_id'] . "\t"; // libellé
$ciel_list .= "" . "\t"; // Echéancce laisser vide
$ciel_list .= "" . "\t"; // code analytique laisser vide
$ciel_list .= "" . "\t"; // mode de paiement laisser vide
$ciel_list .= chr(13); // \n chr(13) en CRLF
}
} // end if shippingTTC
// DEBIT compte 411
// compte
switch ($order->customer['id']){
case '3':
$compte = '411m000';
break;
case '1':
$compte = '4110000';
break;
default :
$compte = '411s000';
break;
}
$debit = $credit;
// montant
if ($payment_method == '3x') {
$tiers = tep_round($debit/3, 2);
$montant['1'] = virgule($tiers);
$montant['2'] = virgule($debit - 2 * $tiers);
$montant['3'] = virgule($tiers);
} else {
$montant['3'] = virgule($debit);
}
$i=3;
if ($payment_method == '3x') $i=1;
do {
if ($i==1) $date_ech = echeance($date, 30);
if ($i==2) $date_ech = echeance($date, 60);
if ($i==3) $date_ech = '';
$ciel_list .= "VT" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= $compte . "\t"; // N° compte
$ciel_list .= $montant[$i] . "\t"; // débit (total)
$ciel_list .= "" . "\t"; // crédit laisser vide
$ciel_list .= $orders['orders_id'] . '-' . $payment_method . "\t"; // libellé
$ciel_list .= $date_ech . "\t"; // Echéancce
$ciel_list .= "" . "\t"; // code analytique
$ciel_list .= $payment_method . "\t"; // mode de paiement
$ciel_list .= chr(13); // \n chr(13) en CRLF
$i++;
} while($i < 4);
// Paiement CHQ CADEAU
$custom_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "' and class='ot_custom'");
$custom = tep_db_fetch_array($custom_query);
$custom = $custom['value'];
$value = virgule (-$custom);
if ($custom && $custom!='0'){
$cado_query = tep_db_query("select title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "' and class='ot_custom'");
$cado = tep_db_fetch_array($cado_query);
$cado = $cado['title'];
$ciel_list .= "OD" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= '4191000' . "\t"; // N° compte
$ciel_list .= $value . "\t"; // débit (cheque cadeau)
$ciel_list .= "" . "\t"; // crédit (détail)
$ciel_list .= $cado . "(" . $orders['orders_id'] . ")" . "\t"; // libellé
$ciel_list .= "" . "\t"; // Echéancce laisser vide
$ciel_list .= "" . "\t"; // code analytique laisser vide
$ciel_list .= '' . "\t"; // mode de paiement laisser vide
$ciel_list .= chr(13); // \n chr(13) en CRLF
$ciel_list .= "OD" . chr(9); // \t ou chr(9)
$ciel_list .= $date . "\t"; // date
$ciel_list .= $compte . "\t"; // N° compte
$ciel_list .= "" . "\t"; // débit (cheque cadeau)
$ciel_list .= $value . "\t"; // crédit (détail)
$ciel_list .= $cado . "(" . $orders['orders_id'] . ")" . "\t"; // libellé
$ciel_list .= "" . "\t"; // Echéancce laisser vide
$ciel_list .= "" . "\t"; // code analytique laisser vide
$ciel_list .= '' . "\t"; // mode de paiement laisser vide
$ciel_list .= chr(13); // \n chr(13) en CRLF
} // end if custom
// CONTROLE
if ($credit - $totalTTC + $custom> 0.011 || $credit - $totalTTC + $custom < -0.011) {
$error = 1;
break;
}
} // enf if totalTTC
} // end while orders
if ($error ==1) {
$messageStack->add_session('erreur sur la commande <b>' . $orders['orders_id'] .'</b><br/> credit = ' . $credit .'<br> totalTTC = ' . $totalTTC .'<br> chèque cadeau = ' . $custom, 'error');
tep_redirect(tep_href_link('export_ciel.php'));
break;
} else {
$fp= fopen($dossier . $file,"w");
fputs($fp, $ciel_list);
fclose($fp);
$fp= fopen($dossier . 'derniere.txt',"w");
fputs($fp, $to+1);
fclose($fp);
$messageStack->add_session('Le fichier d\'export a été généré correctement', 'success');
tep_redirect(tep_href_link('export_ciel.php'));
break;
}
}
}
if (is_file($dossier . 'derniere.txt')) {
$fp= fopen($dossier . 'derniere.txt',"r");
$from = fgets($fp,32);
fclose($fp);
} else $from = 1;
// mise de la commande finale par défaut
$orders_query = tep_db_query("SELECT orders_id from " . TABLE_ORDERS . " ORDER by orders_id DESC LIMIT 1");
$orders = tep_db_fetch_array($orders_query);
$last = $orders['orders_id'];
// $to = 100 * tep_round(($last - 100)/100, 1);
// taille et date du dernier fichier téléchargé
if (is_file($dossier . $file)) {
$sizefile = filesize($dossier . $file);
$sizeformatted = sprintf("%0.0f octets", $sizefile);
$datefile = strftime(DATE_FORMAT_SHORT, filemtime($dossier . $file));
}
?>
<!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=iso-8859-1">
<title>Export Ciel</title>
<link rel="stylesheet" type="text/css" href="includes/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="3">
<tr>
<td width="5%" valign="top"> </td>
<!-- body_text //-->
<td width="95%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading">Export Ciel Compta</td>
</tr>
</table></td>
</tr> <!--titre //-->
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>
<tr>
<td class="main">Le dernier fichier a été généré le "<b><?php echo $datefile; ?></b>" jusqu'à la commande "<b><?php echo $from - 1; ?></b>". La dernière commande passée est la <b><?php echo $last; ?></b>.</td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '20'); ?></td>
</tr>
<tr>
<td class="pageHeading">Générer un nouveau fichier</b></td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="10px"><?php echo tep_draw_form('orders', 'export_ciel.php?action=create_file', '', 'post'); ?>
<tr>
<td class="main">de la commande</td>
<td class="main"><?php echo tep_draw_input_field('from', $from) ?></td>
<td class="main">à la commande</td>
<td class="main"><?php echo tep_draw_input_field('to', $to) ?></td>
<td class="main"><?php echo tep_image_submit('button_save.gif', 'sauver') ?></td>
</tr>
</form></table></td>
</tr> <!--form orders //-->
<tr>
<td><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="main">
<?php
if (is_file($dossier . $file)) {
echo 'Télécharger (clic droit, enregister sous) ou copier/coller dans un fichier txt-> <a href="export_ciel/export_ciel.txt" target="_blank\">' . '<font color="red">' . $sizeformatted . ' du ' . $datefile . '</font></a>';
} else echo 'Pas de fichier dans ' . $dossier; ?>
</td>
</tr>
</table></td>
</tr> <!--export //-->
<!-- body_text_eof //-->
</table>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
Je me répète, mais
ce code ne pourra pas être utilisé tel quel et je n'en assurerai pas le support

Il faudra bien sûr créer le dossier export_ciel qui accueillera le fichier texte et modifier les lignes de code pour s'adapter à tes besoin (chèque cadeau, 3x sans frais, numéros de compte, mode de paiements...) Mais le code est limpide et linéaire, facile à suivre.
Je te laisse libre de l'adapter à tes besoins
Bon code