From 1260171ab010c50c4de22932360f3595b182a280 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Mon, 11 Apr 2005 14:45:29 +0000 Subject: [PATCH] =?UTF-8?q?Gestion=20de=20la=20reg=E9n=E9ration=20d'un=20r?= =?UTF-8?q?apport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/export/index.php | 79 +++++++++-------- htdocs/compta/export/liste.php | 8 +- .../export/modules/compta.export.class.php | 21 +++-- .../modules/compta.export.poivre.class.php | 85 ++++++++++++------- 4 files changed, 115 insertions(+), 78 deletions(-) diff --git a/htdocs/compta/export/index.php b/htdocs/compta/export/index.php index 36359516ea8..85d80082b0f 100644 --- a/htdocs/compta/export/index.php +++ b/htdocs/compta/export/index.php @@ -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 ''; +print '
Nouvel Export
'; + +print '
'; print '
'; -print '
Nouvel Export
'; +$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 ''; +print ''; +print ''; +print ''; +print "
TypeNb
Factures'.$nbfac.'
Paiements'.$nbp.'
\n"; + +print '
'; $dir = DOL_DATA_ROOT."/compta/export/"; -print '
'; -print ''; +print '
'; print ''; print ''; print ''; @@ -87,37 +125,6 @@ while (($file = readdir($handle))!==false) print "
'.$langs->trans("Name").''.$langs->trans("Date").'
"; -print '
'; - -$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 ''; -print ''; -print ''; -print ''; -print "
TypeNb
Factures'.$nbfac.'
Paiements'.$nbp.'
\n"; - print '
'; diff --git a/htdocs/compta/export/liste.php b/htdocs/compta/export/liste.php index e0b1d12e788..a925a9c195b 100644 --- a/htdocs/compta/export/liste.php +++ b/htdocs/compta/export/liste.php @@ -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 ''; print_liste_field_titre($langs->trans("Ref"),"liste.php","ec.ref"); + print_liste_field_titre($langs->trans("Date"),"liste.php","ec.date_export"); - print "\n"; + print "-\n"; $var=True; @@ -85,7 +86,8 @@ if ($result) print ""; print ''.stripslashes($obj->ref).''; - + print ''.strftime("%a %e %b %Y %H:%M:%S",$obj->date_export).''; + print 'Regénérer'; print "\n"; $i++; } diff --git a/htdocs/compta/export/modules/compta.export.class.php b/htdocs/compta/export/modules/compta.export.class.php index 3fae7d76b02..c103d540f9d 100644 --- a/htdocs/compta/export/modules/compta.export.class.php +++ b/htdocs/compta/export/modules/compta.export.class.php @@ -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; diff --git a/htdocs/compta/export/modules/compta.export.poivre.class.php b/htdocs/compta/export/modules/compta.export.poivre.class.php index 9785aa7eec0..bfb1bc96e9e 100644 --- a/htdocs/compta/export/modules/compta.export.poivre.class.php +++ b/htdocs/compta/export/modules/compta.export.poivre.class.php @@ -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;