Gestion de la regnration d'un rapport
This commit is contained in:
parent
9f078e1d2d
commit
1260171ab0
@ -38,7 +38,15 @@ if ($_GET["action"] == 'export')
|
||||
include_once DOL_DOCUMENT_ROOT.'/compta/export/modules/compta.export.class.php';
|
||||
|
||||
$exc = new ComptaExport($db, $user, 'Poivre');
|
||||
$exc->Export();
|
||||
|
||||
if($_GET["id"] > 0)
|
||||
{
|
||||
$exc->Export($_GET["id"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$exc->Export();
|
||||
}
|
||||
|
||||
print $exc->error_message;
|
||||
|
||||
@ -57,16 +65,46 @@ llxHeader('','Compta - Export');
|
||||
|
||||
print_titre("Export Comptable");
|
||||
|
||||
print '<table border="0" width="100%">';
|
||||
print '<br><a href="index.php?action=export">Nouvel Export</a><br>';
|
||||
|
||||
|
||||
print '<table border="0" width="100%" cellspacing="4">';
|
||||
print '<tr><td valign="top" width="30%">';
|
||||
|
||||
print '<br><a href="index.php?action=export">Nouvel Export</a><br>';
|
||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."facturedet";
|
||||
$sql .= " WHERE fk_export_compta = 0";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$row = $db->fetch_row($resql);
|
||||
$nbfac = $row[0];
|
||||
|
||||
$db->free($resql);
|
||||
}
|
||||
|
||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."paiement";
|
||||
$sql .= " WHERE fk_export_compta = 0";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$row = $db->fetch_row($resql);
|
||||
$nbp = $row[0];
|
||||
|
||||
$db->free($resql);
|
||||
}
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td>Type</td><td>Nb</td></tr>';
|
||||
print '<tr><td>Factures</td><td align="right">'.$nbfac.'</td></tr>';
|
||||
print '<tr><td>Paiements</td><td align="right">'.$nbp.'</td></tr>';
|
||||
print "</table>\n";
|
||||
|
||||
print '</td><td valign="top" width="70%">';
|
||||
|
||||
$dir = DOL_DATA_ROOT."/compta/export/";
|
||||
|
||||
print '<br>';
|
||||
print '<table class="noborder">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Name").'</td>';
|
||||
print '<td>'.$langs->trans("Date").'</td>';
|
||||
@ -87,37 +125,6 @@ while (($file = readdir($handle))!==false)
|
||||
|
||||
print "</table>";
|
||||
|
||||
print '</td><td valign="top">';
|
||||
|
||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."facturedet";
|
||||
$sql .= " WHERE fk_export_compta = 0";
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$row = $db->fetch_row($result);
|
||||
$nbfac = $row[0];
|
||||
|
||||
$db->free($result);
|
||||
}
|
||||
|
||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."paiement";
|
||||
$sql .= " WHERE fk_export_compta = 0";
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$row = $db->fetch_row($result);
|
||||
$nbp = $row[0];
|
||||
|
||||
$db->free($result);
|
||||
}
|
||||
|
||||
print '<table class="noborder">';
|
||||
print '<tr class="liste_titre"><td>Type</td><td>Nb</td></tr>';
|
||||
print '<tr><td>Factures</td><td align="right">'.$nbfac.'</td></tr>';
|
||||
print '<tr><td>Paiements</td><td align="right">'.$nbp.'</td></tr>';
|
||||
print "</table>\n";
|
||||
|
||||
print '</td></tr></table>';
|
||||
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ if ($sortfield == "") $sortfield="ec.date_export";
|
||||
*
|
||||
*/
|
||||
|
||||
$sql = "SELECT ec.date_export, ec.ref";
|
||||
$sql = "SELECT ec.rowid,".$db->pdate("ec.date_export")." as date_export, ec.ref";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."export_compta as ec";
|
||||
|
||||
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
|
||||
@ -70,8 +70,9 @@ if ($result)
|
||||
print '<tr class="liste_titre">';
|
||||
|
||||
print_liste_field_titre($langs->trans("Ref"),"liste.php","ec.ref");
|
||||
print_liste_field_titre($langs->trans("Date"),"liste.php","ec.date_export");
|
||||
|
||||
print "</tr>\n";
|
||||
print "<td>-</td></tr>\n";
|
||||
|
||||
$var=True;
|
||||
|
||||
@ -85,7 +86,8 @@ if ($result)
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
print '<td>'.stripslashes($obj->ref).'</td>';
|
||||
|
||||
print '<td>'.strftime("%a %e %b %Y %H:%M:%S",$obj->date_export).'</td>';
|
||||
print '<td><a href="index.php?action=export&id='.$obj->rowid.'">Regénérer</a></td>';
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -54,8 +54,10 @@ class ComptaExport
|
||||
\brief Lecture des factures dans la base
|
||||
*/
|
||||
|
||||
function ReadLines()
|
||||
function ReadLines($id=0)
|
||||
{
|
||||
dolibarr_syslog("ComptaExport::ReadLines id=".$id);
|
||||
|
||||
$error = 0;
|
||||
|
||||
$sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as datef";
|
||||
@ -76,7 +78,7 @@ class ComptaExport
|
||||
|
||||
$sql .= " AND l.fk_code_ventilation <> 0 ";
|
||||
|
||||
$sql .= " AND l.fk_export_compta = 0";
|
||||
$sql .= " AND l.fk_export_compta = ".$id;
|
||||
|
||||
$sql .= " AND c.rowid = l.fk_code_ventilation";
|
||||
|
||||
@ -125,14 +127,15 @@ class ComptaExport
|
||||
\brief Lecture des paiements dans la base
|
||||
*/
|
||||
|
||||
function ReadLinesPayment()
|
||||
function ReadLinesPayment($id=0)
|
||||
{
|
||||
dolibarr_syslog("ComptaExport::ReadLinesPayment id=".$id);
|
||||
$error = 0;
|
||||
|
||||
$sql = "SELECT p.rowid as paymentid, f.facnumber";
|
||||
$sql .= " ,".$this->db->pdate("p.datep")." as datep";
|
||||
$sql .= " , pf.amount";
|
||||
$sql .= " ,s.nom, s.code_compta";
|
||||
$sql .= " , s.nom, s.code_compta";
|
||||
$sql .= " , cp.libelle, f.increment";
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
|
||||
@ -141,7 +144,7 @@ class ComptaExport
|
||||
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
|
||||
|
||||
$sql .= " WHERE p.fk_export_compta = 0";
|
||||
$sql .= " WHERE p.fk_export_compta = ".$id;
|
||||
$sql .= " AND p.rowid = pf.fk_paiement";
|
||||
$sql .= " AND cp.id = p.fk_paiement";
|
||||
$sql .= " AND f.rowid = pf.fk_facture";
|
||||
@ -197,14 +200,14 @@ class ComptaExport
|
||||
\brief Créé le fichier d'export
|
||||
*/
|
||||
|
||||
function Export()
|
||||
function Export($id=0)
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
dolibarr_syslog("ComptaExport::Export");
|
||||
|
||||
$error += $this->ReadLines();
|
||||
$error += $this->ReadLinesPayment();
|
||||
$error += $this->ReadLines($id);
|
||||
$error += $this->ReadLinesPayment($id);
|
||||
|
||||
dolibarr_syslog("ComptaExport::Export Lignes de factures : ".sizeof($this->linec));
|
||||
dolibarr_syslog("ComptaExport::Export Lignes de paiements : ".sizeof($this->linep));
|
||||
@ -217,7 +220,7 @@ class ComptaExport
|
||||
|
||||
$objexport = new $objexport_name($this->db, $this->user);
|
||||
|
||||
$objexport->Export($this->linec, $this->linep);
|
||||
$objexport->Export($this->linec, $this->linep, $id);
|
||||
|
||||
$this->id = $objexport->id;
|
||||
$this->ref = $objexport->ref;
|
||||
|
||||
@ -74,7 +74,11 @@ class ComptaExportPoivre
|
||||
return 0;
|
||||
}
|
||||
|
||||
function Export($linec, $linep)
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function Export($linec, $linep, $id=0)
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
@ -85,48 +89,70 @@ class ComptaExportPoivre
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$dt = strftime('EC%y%m', time());
|
||||
|
||||
$sql = "SELECT count(ref) FROM ".MAIN_DB_PREFIX."export_compta";
|
||||
$sql .= " WHERE ref like '$dt%'";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
if ($id == 0)
|
||||
{
|
||||
$row = $this->db->fetch_row();
|
||||
$cc = $row[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
dolibarr_syslog("ComptaExportPoivre::Export Erreur Select");
|
||||
}
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$ref = $dt . substr("000".$cc, -2);
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."export_compta (ref, date_export, fk_user)";
|
||||
$sql .= " VALUES ('$ref', now(),".$this->user->id.")";
|
||||
$dt = strftime('EC%y%m', time());
|
||||
|
||||
$sql = "SELECT count(ref) FROM ".MAIN_DB_PREFIX."export_compta";
|
||||
$sql .= " WHERE ref like '$dt%'";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
|
||||
$this->ref = $ref;
|
||||
$row = $this->db->fetch_row();
|
||||
$cc = $row[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
dolibarr_syslog("ComptaExportPoivre::Export Erreur INSERT");
|
||||
dolibarr_syslog("ComptaExportPoivre::Export Erreur Select");
|
||||
}
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$this->ref = $dt . substr("000".$cc, -2);
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."export_compta (ref, date_export, fk_user)";
|
||||
$sql .= " VALUES ('".$this->ref."', now(),".$this->user->id.")";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."export_compta");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
dolibarr_syslog("ComptaExportPoivre::Export Erreur INSERT");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."export_compta";
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$row = $this->db->fetch_row($resql);
|
||||
$this->ref = $row[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
dolibarr_syslog("ComptaExportPoivre::Export Erreur Select");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
dolibarr_syslog("ComptaExportPoivre::Export ref : $ref");
|
||||
dolibarr_syslog("ComptaExportPoivre::Export ref : ".$this->ref);
|
||||
|
||||
$fxname = DOL_DATA_ROOT."/compta/export/".$ref.".xls";
|
||||
$fxname = DOL_DATA_ROOT."/compta/export/".$this->ref.".xls";
|
||||
|
||||
$workbook = &new writeexcel_workbook($fxname);
|
||||
|
||||
@ -212,7 +238,6 @@ class ComptaExportPoivre
|
||||
// Tag des lignes de factures
|
||||
$n = sizeof($linec);
|
||||
for ( $i = 0 ; $i < $n ; $i++)
|
||||
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet";
|
||||
$sql .= " SET fk_export_compta=".$this->id;
|
||||
@ -238,7 +263,7 @@ class ComptaExportPoivre
|
||||
// EUR pour Monnaie en Euros
|
||||
|
||||
$i = 0;
|
||||
// $j = 0;
|
||||
//$j = 0;
|
||||
$n = sizeof($linep);
|
||||
|
||||
$oldfacture = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user