par
stephforum » 30 oct. 2011, 21:06
Bonjour,
Je suis en train de modifier un fichier php qui genere un csv
Jusque l'a, je n'ai pas eu trop de mal , l'export se passe bien comme je le veu sauf concernant la mise en forme.
Toute les données sont sur une ligne hors cela concerne des ecritures devant etre importer en compta et j'aimerai que la mise en forme manuel que l'on fait depuis excel soit déja faite lors de l'export csv
Voici l'exemple que je cherche à faire :
journal ; compte ; libelé ; debit ; credit ; date ; numero de facture ; ref. lettrage
vt 411 nom client 119.60 01
vt 707 nom client 100 01
vt 445714 nom client 19.6 01
On a le titre pour chaques colonnes et comme cela est des ecritures compta, chaque ligne correspond à un compte par ordre de numero de facture
Voici mon fichier php pour mieux comprendre sur quoi je part
Code : Tout sélectionner
<?php
class Compta extends Module
{
public $fieldlist=array(
0=>'"VT"',
1=>'O.`id_order`',
2=>'CONCAT(AD.`id_customer`, " . ", AD.`lastname`, " ", AD.`firstname`, " ", "commande"," ", O.`id_order`)',
3=>'O.`payment`',
4=>'O.`total_discounts`',
5=>'O.`total_paid`',
6=>'O.`total_paid_real`',
7=>'O.`total_products`',
8=>'CONCAT(O.`total_products_wt` - O.`total_products`)',
9=>'O.`total_products_wt`',
10=>'O.`total_shipping`',
11=>'O.`carrier_tax_rate`',
12=>'O.`total_shipping`/ (O.`carrier_tax_rate`+ 100) * O.`carrier_tax_rate`',
13=>'O.`total_shipping` - O.`total_shipping`/ (O.`carrier_tax_rate`+ 100) * O.`carrier_tax_rate`',
14=>'O.`total_wrapping`',
15=>'O.`invoice_number`',
16=>'O.`invoice_date`',
17=>'O.`id_cart`',
18=>'O.`valid`',
19=>'O.date_add'
);
public $fieldnames=array(
0=>'journal',
1=>'Order No',
2=>'Client',
3=>'Payment',
4=>'Total Discounts',
5=>'Total Paid',
6=>'Total Paid Real',
7=>'Total Produit HT',
8=>'TVA produit',
9=>'Total product TTC',
10=>'frais de port net',
11=>'Taux TVA transporteur',
12=>'valeur TVA f.port',
13=>'port ht',
14=>'Total Wrapping',
15=>'numero de facture',
16=>'date de facture',
17=>'Numero de panier',
18=>'valide',
19=>'Date Added'
);
function __construct()
{
$this->name = 'compta';
$this->tab = 'billing_invoicing';
$this->version = '1.0';
/* The parent construct is required for translations */
parent::__construct();
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Export factures');
$this->description = $this->l('module pour exporter les factures en compta.');
}
function install()
{
if (!parent::install())
return false;
// Trunk file if already exists with contents
/*
if (!$fd = @fopen(dirname(__FILE__).'/editorial.xml', 'w'))
return false;
@fclose($fd);
*/
}
function getContent()
{
/* display the module name */
$this->_html = '<h2>'.$this->displayName.'</h2>';
/* update the editorial xml */
if (isset($_POST['submitFilter']))
{
$fields=array();
$titles=array();
foreach($_POST['eofields'] AS $fieldno){
$fields[]=$this->fieldlist[$fieldno];
$titles[]=$this->fieldnames[$fieldno];
}
$premiere_fact='0';
$sql='SELECT '.implode(', ', $fields).' FROM '._DB_PREFIX_.'orders AS O, '._DB_PREFIX_.'customer AS C, '._DB_PREFIX_.'address AS AD, '._DB_PREFIX_.'address AS AI WHERE AI.id_address=id_address_invoice AND AD.id_address=id_address_delivery AND C.id_customer=O.id_customer AND valid = 1 AND invoice_number > '.$premiere_fact.' order by invoice_number';
$orderlist = Db::getInstance()->ExecuteS($sql);
$f=fopen(dirname(__FILE__).'/ecritures.csv', 'w');
fwrite($f, implode('; ', $titles)."\r\n");
foreach($orderlist AS $order){
fwrite($f, implode('; ', $order)."\r\n");
}
Tools::redirect('modules/compta/ecritures.csv');
}else{
/* display the editorial's form */
$this->_html.=$this->_displayForm();
if (file_exists(dirname(__FILE__).'/ecritures.csv')){
$this->_html.='<p><a href="../modules/compta/ecritures.csv">'.$this->l('Download Last Report').'</a></p>';
}
$this->_html.='<p>
Telecharger <a href="../modules/compta/exportcompta.php" target="_blank" style="text-decoration:underline; color:blue;">ecriture</a>.
</p>';
return $this->_html;
}
}
private function _displayForm()
{
$form='<form method="post">';
$form.='<table>';
$form.='
<tr>
<td height="30">'.$this->l('Check the fields you would like to export.').'</td>
</tr>';
$form.='
<tr>
<td height="30"><input type="button" onClick="checkDelBoxes(this.form, \'eofields[]\', true)" value="'.$this->l('Check All').'" />
<input type="button" onClick="checkDelBoxes(this.form, \'eofields[]\', false)" value="'.$this->l('Uncheck All').'" /></td>
</tr>';
foreach($this->fieldnames as $key=>$name){
$selected='';
if(isset($_POST['eofields'])){
if(in_array($key, $_POST['eofields'])){
$selected=' checked';
}
}
$form.='
<tr>
<td style="height:30px;" valign="top">
<label for="field'.$key.'">'.$this->l($name).'</label> <input type="checkbox" name="eofields[]" id="field'.$key.'" value="'.$key.'"'.$selected.' />
</td>
</tr>';
}
$form.='
<tr>
<td height="30"><input type="submit" name="submitFilter" value="'.$this->l('Generate Report').'" /></td>
</tr>';
$form.='</table>';
$form.='</form>';
return $form;
}
}
merci beaucoup pour votre aide

Bonjour,
Je suis en train de modifier un fichier php qui genere un csv :D
Jusque l'a, je n'ai pas eu trop de mal , l'export se passe bien comme je le veu sauf concernant la mise en forme.
Toute les données sont sur une ligne hors cela concerne des ecritures devant etre importer en compta et j'aimerai que la mise en forme manuel que l'on fait depuis excel soit déja faite lors de l'export csv :D
Voici l'exemple que je cherche à faire :
journal ; compte ; libelé ; debit ; credit ; date ; numero de facture ; ref. lettrage
vt 411 nom client 119.60 01
vt 707 nom client 100 01
vt 445714 nom client 19.6 01
On a le titre pour chaques colonnes et comme cela est des ecritures compta, chaque ligne correspond à un compte par ordre de numero de facture
Voici mon fichier php pour mieux comprendre sur quoi je part :mrgreen:
[code]<?php
class Compta extends Module
{
public $fieldlist=array(
0=>'"VT"',
1=>'O.`id_order`',
2=>'CONCAT(AD.`id_customer`, " . ", AD.`lastname`, " ", AD.`firstname`, " ", "commande"," ", O.`id_order`)',
3=>'O.`payment`',
4=>'O.`total_discounts`',
5=>'O.`total_paid`',
6=>'O.`total_paid_real`',
7=>'O.`total_products`',
8=>'CONCAT(O.`total_products_wt` - O.`total_products`)',
9=>'O.`total_products_wt`',
10=>'O.`total_shipping`',
11=>'O.`carrier_tax_rate`',
12=>'O.`total_shipping`/ (O.`carrier_tax_rate`+ 100) * O.`carrier_tax_rate`',
13=>'O.`total_shipping` - O.`total_shipping`/ (O.`carrier_tax_rate`+ 100) * O.`carrier_tax_rate`',
14=>'O.`total_wrapping`',
15=>'O.`invoice_number`',
16=>'O.`invoice_date`',
17=>'O.`id_cart`',
18=>'O.`valid`',
19=>'O.date_add'
);
public $fieldnames=array(
0=>'journal',
1=>'Order No',
2=>'Client',
3=>'Payment',
4=>'Total Discounts',
5=>'Total Paid',
6=>'Total Paid Real',
7=>'Total Produit HT',
8=>'TVA produit',
9=>'Total product TTC',
10=>'frais de port net',
11=>'Taux TVA transporteur',
12=>'valeur TVA f.port',
13=>'port ht',
14=>'Total Wrapping',
15=>'numero de facture',
16=>'date de facture',
17=>'Numero de panier',
18=>'valide',
19=>'Date Added'
);
function __construct()
{
$this->name = 'compta';
$this->tab = 'billing_invoicing';
$this->version = '1.0';
/* The parent construct is required for translations */
parent::__construct();
$this->page = basename(__FILE__, '.php');
$this->displayName = $this->l('Export factures');
$this->description = $this->l('module pour exporter les factures en compta.');
}
function install()
{
if (!parent::install())
return false;
// Trunk file if already exists with contents
/*
if (!$fd = @fopen(dirname(__FILE__).'/editorial.xml', 'w'))
return false;
@fclose($fd);
*/
}
function getContent()
{
/* display the module name */
$this->_html = '<h2>'.$this->displayName.'</h2>';
/* update the editorial xml */
if (isset($_POST['submitFilter']))
{
$fields=array();
$titles=array();
foreach($_POST['eofields'] AS $fieldno){
$fields[]=$this->fieldlist[$fieldno];
$titles[]=$this->fieldnames[$fieldno];
}
$premiere_fact='0';
$sql='SELECT '.implode(', ', $fields).' FROM '._DB_PREFIX_.'orders AS O, '._DB_PREFIX_.'customer AS C, '._DB_PREFIX_.'address AS AD, '._DB_PREFIX_.'address AS AI WHERE AI.id_address=id_address_invoice AND AD.id_address=id_address_delivery AND C.id_customer=O.id_customer AND valid = 1 AND invoice_number > '.$premiere_fact.' order by invoice_number';
$orderlist = Db::getInstance()->ExecuteS($sql);
$f=fopen(dirname(__FILE__).'/ecritures.csv', 'w');
fwrite($f, implode('; ', $titles)."\r\n");
foreach($orderlist AS $order){
fwrite($f, implode('; ', $order)."\r\n");
}
Tools::redirect('modules/compta/ecritures.csv');
}else{
/* display the editorial's form */
$this->_html.=$this->_displayForm();
if (file_exists(dirname(__FILE__).'/ecritures.csv')){
$this->_html.='<p><a href="../modules/compta/ecritures.csv">'.$this->l('Download Last Report').'</a></p>';
}
$this->_html.='<p>
Telecharger <a href="../modules/compta/exportcompta.php" target="_blank" style="text-decoration:underline; color:blue;">ecriture</a>.
</p>';
return $this->_html;
}
}
private function _displayForm()
{
$form='<form method="post">';
$form.='<table>';
$form.='
<tr>
<td height="30">'.$this->l('Check the fields you would like to export.').'</td>
</tr>';
$form.='
<tr>
<td height="30"><input type="button" onClick="checkDelBoxes(this.form, \'eofields[]\', true)" value="'.$this->l('Check All').'" />
<input type="button" onClick="checkDelBoxes(this.form, \'eofields[]\', false)" value="'.$this->l('Uncheck All').'" /></td>
</tr>';
foreach($this->fieldnames as $key=>$name){
$selected='';
if(isset($_POST['eofields'])){
if(in_array($key, $_POST['eofields'])){
$selected=' checked';
}
}
$form.='
<tr>
<td style="height:30px;" valign="top">
<label for="field'.$key.'">'.$this->l($name).'</label> <input type="checkbox" name="eofields[]" id="field'.$key.'" value="'.$key.'"'.$selected.' />
</td>
</tr>';
}
$form.='
<tr>
<td height="30"><input type="submit" name="submitFilter" value="'.$this->l('Generate Report').'" /></td>
</tr>';
$form.='</table>';
$form.='</form>';
return $form;
}
}
[/code]
merci beaucoup pour votre aide :D