Corrections diverses sur génération des rapport de paiement.

Si on est un utilisateur externe, le fichier est généré dans un rep privé.
This commit is contained in:
Laurent Destailleur 2006-08-04 19:05:34 +00:00
parent da56232460
commit aadbf18c22
4 changed files with 172 additions and 176 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,7 +18,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** \file htdocs/compta/paiement/rapport.php /** \file htdocs/compta/paiement/rapport.php
@ -36,11 +35,14 @@ $user->getrights("facture");
if (! $user->rights->facture->lire) if (! $user->rights->facture->lire)
accessforbidden(); accessforbidden();
$dir = $conf->compta->dir_output;
$socidp=0; $socidp=0;
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$action = ''; $action = '';
$socidp = $user->societe_id; $socidp = $user->societe_id;
$dir = DOL_DATA_ROOT.'/private/'.$user->id.'/compta';
} }
@ -50,7 +52,6 @@ if (! $year) { $year=date("Y"); }
require("../../includes/modules/rapport/pdf_paiement.class.php"); require("../../includes/modules/rapport/pdf_paiement.class.php");
$dir = $conf->compta->dir_output;
/* /*
@ -64,9 +65,10 @@ if ($_POST["action"] == 'gen')
$year = $_POST["reyear"]; $year = $_POST["reyear"];
} }
llxHeader();
llxHeader();
/* /*
* Affichage liste des paiements * Affichage liste des paiements
* *
@ -80,30 +82,18 @@ print '<input type="hidden" name="action" value="gen">';
$cmonth = date("n", time()); $cmonth = date("n", time());
$syear = date("Y", time()); $syear = date("Y", time());
$strmonth[1] = "Janvier";
$strmonth[2] = "F&eacute;vrier";
$strmonth[3] = "Mars";
$strmonth[4] = "Avril";
$strmonth[5] = "Mai";
$strmonth[6] = "Juin";
$strmonth[7] = "Juillet";
$strmonth[8] = "Ao&ucirc;t";
$strmonth[9] = "Septembre";
$strmonth[10] = "Octobre";
$strmonth[11] = "Novembre";
$strmonth[12] = "D&eacute;cembre";
print '<select name="remonth">'; print '<select name="remonth">';
for ($month = 1 ; $month < 13 ; $month++) for ($month = 1 ; $month < 13 ; $month++)
{ {
if ($month == $cmonth) if ($month == $cmonth)
{ {
print "<option value=\"$month\" selected=\"true\">" . $strmonth[$month]; print "<option value=\"$month\" selected=\"true\">" . dolibarr_print_date(mktime(0,0,0,$month),"%B");
} }
else else
{ {
print "<option value=\"$month\">" . $strmonth[$month]; print "<option value=\"$month\">" . dolibarr_print_date(mktime(0,0,0,$month),"%B");
} }
} }
print "</select>"; print "</select>";
@ -121,48 +111,61 @@ for ($formyear = $syear - 2; $formyear < $syear +1 ; $formyear++)
} }
} }
print "</select>\n"; print "</select>\n";
print '<input type="submit" value="'.$langs->trans("Create").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
print '</form>'; print '</form>';
print '<br>';
clearstatcache(); clearstatcache();
if (is_dir($dir)) { // Affiche lien sur autres années
$found=0;
if (is_dir($dir))
{
$handle=opendir($dir); $handle=opendir($dir);
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_dir($dir.$file) && substr($file, 0, 1) <> '.') if (is_dir($dir.'/'.$file) && ! eregi('^\.',$file))
{ {
print '<a href="rapport.php?year='.$file.'">'.$file.'</a> '; $found=1;
} print '<a href="rapport.php?year='.$file.'">'.$file.'</a> ';
}
} }
} }
if ($year) if ($year)
{ {
if (is_dir($dir.'/'.$year)) { if (is_dir($dir.'/'.$year))
$handle=opendir($dir.'/'.$year); {
print '<br>'; $handle=opendir($dir.'/'.$year);
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre"><td>Rapport</td><td align="right">'.$langs->trans("Size").'</td><td align="right">'.$langs->trans("Date").'</td></tr>'; if ($found) print '<br>';
$var=true; print '<br>';
while (($file = readdir($handle))!==false)
{ print '<table width="100%" class="noborder">';
if (substr($file, 0, 8) == 'paiement') print '<tr class="liste_titre">';
{ print '<td>'.$langs->trans("Reporting").'</td>';
$var=!$var; print '<td align="right">'.$langs->trans("Size").'</td>';
$tfile = $dir . '/'.$year.'/'.$file; print '<td align="right">'.$langs->trans("Date").'</td>';
$relativepath = $year.'/'.$file; print '</tr>';
print "<tr $bc[$var]>".'<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture_paiement&file='.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a></td>'; $var=true;
print '<td align="right">'.filesize($tfile). ' bytes</td>'; while (($file = readdir($handle))!==false)
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($tfile)).'</td></tr>'; {
} if (substr($file, 0, 8) == 'paiement')
} {
print '</table>'; $var=!$var;
} $tfile = $dir . '/'.$year.'/'.$file;
$relativepath = $year.'/'.$file;
print "<tr $bc[$var]>".'<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture_paiement&file='.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a></td>';
print '<td align="right">'.filesize($tfile). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($tfile)).'</td></tr>';
}
}
print '</table>';
}
} }
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -278,7 +278,7 @@ if ($result)
$i++; $i++;
} }
print_barre_liste($titre ,$page, "index.php", '&amp;begin='.$begin.'&amp;view='.$_GET["view"].'&amp;userid='.$_GET["userid"], $sortfield, $sortorder,'',$num); if ($num > $limit) print_barre_liste($titre ,$page, "index.php", '&amp;begin='.$begin.'&amp;view='.$_GET["view"].'&amp;userid='.$_GET["userid"], $sortfield, $sortorder,'',$num);
print "</table>"; print "</table>";

View File

@ -142,7 +142,8 @@ if ($modulepart)
{ {
$accessallowed=1; $accessallowed=1;
} }
$original_file=$conf->compta->dir_output.'/'.$original_file; if ($user->societe_id > 0) $original_file=DOL_DATA_ROOT.'/private/'.$user->id.'/compta/'.$original_file;
else $original_file=$conf->compta->dir_output.'/'.$original_file;
} }
// Wrapping pour les exports de compta // Wrapping pour les exports de compta

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,7 +19,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -41,22 +41,24 @@ class pdf_paiement
/** \brief Constructeur /** \brief Constructeur
\param db handler accès base de donnée \param db handler accès base de donnée
*/ */
function pdf_paiement($db=0) function pdf_paiement($db=0)
{ {
$this->db = $db; global $langs;
$this->description = "Liste des paiements";
$this->url = DOL_URL_ROOT."/document/rapport/" . "paiements" . ".pdf"; $this->db = $db;
$this->description = "Liste des paiements";
$this->tab_top = 30;
$this->url = DOL_URL_ROOT."/document/rapport/" . "paiements" . ".pdf";
$this->line_height = 5;
$this->line_per_page = 25; $this->tab_top = 30;
$this->tab_height = 230;//$this->line_height * $this->line_per_page;
$this->line_height = 5;
} $this->line_per_page = 25;
$this->tab_height = 230; //$this->line_height * $this->line_per_page;
function print_link() }
function print_link()
{ {
if (file_exists($this->file)) if (file_exists($this->file))
{ {
@ -68,13 +70,13 @@ class pdf_paiement
} }
} }
function Header(&$pdf, $page, $pages)
function Header(&$pdf, $page, $pages)
{ {
global $langs;
$pdf->SetFont('Arial','B',12); $pdf->SetFont('Arial','B',12);
$pdf->Text(10, 10, FAC_PDF_INTITULE); $pdf->Text(90, 10, $langs->trans("PaimentsList"));
$pdf->SetFont('Arial','B',12);
$pdf->Text(90, 10, "Liste des paiements encaissés");
$pdf->SetFont('Arial','B',12); $pdf->SetFont('Arial','B',12);
$pdf->Text(11, 16, "Date : " . strftime("%d %b %Y", time())); $pdf->Text(11, 16, "Date : " . strftime("%d %b %Y", time()));
@ -173,110 +175,100 @@ class pdf_paiement
\param month mois du rapport \param month mois du rapport
\param year annee du rapport \param year annee du rapport
*/ */
function write_pdf_file($_dir, $month, $year) function write_pdf_file($_dir, $month, $year)
{ {
if (! file_exists($_dir)) global $langs;
{
umask(0); $dir=$_dir.'/'.$year;
if (! mkdir($_dir, 0755))
{ if (! is_dir($dir))
print "Impossible de créer $_dir !"; {
die; $result=create_exdir($dir);
} if ($result < 0)
{
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return;
}
}
$month = substr("0".$month, strlen("0".$month)-2,2);
$_file = $dir . "/paiements-$month-$year" . ".pdf";
$pdf = new FPDF('P','mm','A4');
$pdf->Open();
$sql = "SELECT ".$this->db->pdate("p.datep")." as dp, f.facnumber";
$sql .= ", c.libelle as paiement_type, p.num_paiement";
$sql .= ", p.amount as paiement_amount, f.total_ttc as facture_amount ";
$sql .= ", pf.amount as pf_amount ";
$sql .= ", p.rowid as prowid";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f, ";
$sql .= MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf";
$sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
$sql .= " AND date_format(p.datep, '%Y') = " . $year;
$sql .= " AND p.fk_paiement = c.id ";
// $sql .= " AND date_format(p.datep, '%m%Y') = " . $month.$year;
$sql .= " ORDER BY p.datep ASC, pf.fk_paiement ASC";
$result = $this->db->query($sql);
// print $sql ;
if ($result)
{
$lignes = $this->db->num_rows($result);
$i = 0;
$var=True;
while ($i < $lignes)
{
$objp = $this->db->fetch_object($result);
$var=!$var;
$lines[$i][0] = $objp->facnumber;
$lines[$i][1] = strftime("%d %B %Y",$objp->dp);
$lines[$i][2] = $objp->paiement_type ;
$lines[$i][3] = $objp->num_paiement;
$lines[$i][4] = price($objp->paiement_amount);
$lines[$i][5] = price($objp->facture_amount);
$lines[$i][6] = price($objp->pf_amount);
$lines[$i][7] = price($objp->prowid);
$i++;
}
}
$pages = intval($lignes / $this->line_per_page);
if (($lignes % $this->line_per_page)>0)
{
$pages++;
}
if ($pages == 0)
{
// force à générer au moins une page si le rapport ne contient aucune ligne
$pages = 1;
}
/*
for ($i = 0 ; $i < $pages ; $i++)
{
$pdf->AddPage();
$this->Header($pdf, $i+1, $pages);
$this->Body($pdf, $i+1, $lines);
}
*/
$pdf->AddPage();
$this->Header($pdf, 1, $pages);
$this->Body($pdf, 1, $lines);
/*
*
*/
$pdf->Output($_file);
} }
$_dir = $_dir . '/' . $year . '/';
if (! file_exists($_dir))
{
umask(0);
if (! mkdir($_dir, 0755))
{
print "Impossible de créer $_dir !";
die;
}
}
$month = substr("0".$month, strlen("0".$month)-2,2);
$_file = $_dir . "paiements-$month-$year" . ".pdf";
$pdf = new FPDF('P','mm','A4');
$pdf->Open();
/*
*
*/
$sql = "SELECT ".$this->db->pdate("p.datep")." as dp, f.facnumber";
$sql .= ", c.libelle as paiement_type, p.num_paiement";
$sql .= ", p.amount as paiement_amount, f.total_ttc as facture_amount ";
$sql .= ", pf.amount as pf_amount ";
$sql .= ", p.rowid as prowid";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f, ";
$sql .= MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf";
$sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
$sql .= " AND date_format(p.datep, '%Y') = " . $year;
$sql .= " AND p.fk_paiement = c.id ";
// $sql .= " AND date_format(p.datep, '%m%Y') = " . $month.$year;
$sql .= " ORDER BY p.datep ASC, pf.fk_paiement ASC";
$result = $this->db->query($sql);
// print $sql ;
if ($result)
{
$lignes = $this->db->num_rows();
$i = 0;
$var=True;
while ($i < $lignes)
{
$objp = $this->db->fetch_object($result);
$var=!$var;
$lines[$i][0] = $objp->facnumber;
$lines[$i][1] = strftime("%d %B %Y",$objp->dp);
$lines[$i][2] = $objp->paiement_type ;
$lines[$i][3] = $objp->num_paiement;
$lines[$i][4] = price($objp->paiement_amount);
$lines[$i][5] = price($objp->facture_amount);
$lines[$i][6] = price($objp->pf_amount);
$lines[$i][7] = price($objp->prowid);
$i++;
}
}
$pages = intval($lignes / $this->line_per_page);
if (($lignes % $this->line_per_page)>0)
{
$pages++;
}
if ($pages == 0)
{
// force à générer au moins une page si le rapport ne contient aucune ligne
$pages = 1;
}
/*
for ($i = 0 ; $i < $pages ; $i++)
{
$pdf->AddPage();
$this->Header($pdf, $i+1, $pages);
$this->Body($pdf, $i+1, $lines);
}
*/
$pdf->AddPage();
$this->Header($pdf, 1, $pages);
$this->Body($pdf, 1, $lines);
/*
*
*/
$pdf->Output($_file);
}
} }