Corrections diverses sur gnration des rapport de paiement.

Si on est un utilisateur externe, le fichier est gnr 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
/* 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
* it under the terms of the GNU General Public License as published by
@ -18,7 +18,6 @@
*
* $Id$
* $Source$
*
*/
/** \file htdocs/compta/paiement/rapport.php
@ -36,11 +35,14 @@ $user->getrights("facture");
if (! $user->rights->facture->lire)
accessforbidden();
$dir = $conf->compta->dir_output;
$socidp=0;
if ($user->societe_id > 0)
{
$action = '';
$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");
$dir = $conf->compta->dir_output;
/*
@ -64,9 +65,10 @@ if ($_POST["action"] == 'gen')
$year = $_POST["reyear"];
}
llxHeader();
llxHeader();
/*
* Affichage liste des paiements
*
@ -80,30 +82,18 @@ print '<input type="hidden" name="action" value="gen">';
$cmonth = date("n", 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++)
{
if ($month == $cmonth)
{
print "<option value=\"$month\" selected=\"true\">" . $strmonth[$month];
}
else
{
print "<option value=\"$month\">" . $strmonth[$month];
}
if ($month == $cmonth)
{
print "<option value=\"$month\" selected=\"true\">" . dolibarr_print_date(mktime(0,0,0,$month),"%B");
}
else
{
print "<option value=\"$month\">" . dolibarr_print_date(mktime(0,0,0,$month),"%B");
}
}
print "</select>";
@ -121,48 +111,61 @@ for ($formyear = $syear - 2; $formyear < $syear +1 ; $formyear++)
}
}
print "</select>\n";
print '<input type="submit" value="'.$langs->trans("Create").'">';
print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
print '</form>';
print '<br>';
clearstatcache();
if (is_dir($dir)) {
// Affiche lien sur autres années
$found=0;
if (is_dir($dir))
{
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{
if (is_dir($dir.$file) && substr($file, 0, 1) <> '.')
{
print '<a href="rapport.php?year='.$file.'">'.$file.'</a> ';
}
if (is_dir($dir.'/'.$file) && ! eregi('^\.',$file))
{
$found=1;
print '<a href="rapport.php?year='.$file.'">'.$file.'</a> ';
}
}
}
if ($year)
{
if (is_dir($dir.'/'.$year)) {
$handle=opendir($dir.'/'.$year);
print '<br>';
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>';
$var=true;
while (($file = readdir($handle))!==false)
{
if (substr($file, 0, 8) == 'paiement')
{
$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>';
}
if (is_dir($dir.'/'.$year))
{
$handle=opendir($dir.'/'.$year);
if ($found) print '<br>';
print '<br>';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Reporting").'</td>';
print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td align="right">'.$langs->trans("Date").'</td>';
print '</tr>';
$var=true;
while (($file = readdir($handle))!==false)
{
if (substr($file, 0, 8) == 'paiement')
{
$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();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
llxFooter('$Date$ - $Revision$');
?>

View File

@ -278,7 +278,7 @@ if ($result)
$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>";

View File

@ -142,7 +142,8 @@ if ($modulepart)
{
$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

View File

@ -1,5 +1,6 @@
<?php
/* 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
* it under the terms of the GNU General Public License as published by
@ -18,7 +19,6 @@
*
* $Id$
* $Source$
*
*/
/**
@ -41,22 +41,24 @@ class pdf_paiement
/** \brief Constructeur
\param db handler accès base de donnée
*/
function pdf_paiement($db=0)
function pdf_paiement($db=0)
{
$this->db = $db;
$this->description = "Liste des paiements";
global $langs;
$this->url = DOL_URL_ROOT."/document/rapport/" . "paiements" . ".pdf";
$this->tab_top = 30;
$this->line_height = 5;
$this->line_per_page = 25;
$this->tab_height = 230;//$this->line_height * $this->line_per_page;
}
function print_link()
$this->db = $db;
$this->description = "Liste des paiements";
$this->url = DOL_URL_ROOT."/document/rapport/" . "paiements" . ".pdf";
$this->tab_top = 30;
$this->line_height = 5;
$this->line_per_page = 25;
$this->tab_height = 230; //$this->line_height * $this->line_per_page;
}
function print_link()
{
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->Text(10, 10, FAC_PDF_INTITULE);
$pdf->SetFont('Arial','B',12);
$pdf->Text(90, 10, "Liste des paiements encaissés");
$pdf->Text(90, 10, $langs->trans("PaimentsList"));
$pdf->SetFont('Arial','B',12);
$pdf->Text(11, 16, "Date : " . strftime("%d %b %Y", time()));
@ -173,110 +175,100 @@ class pdf_paiement
\param month mois 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))
{
umask(0);
if (! mkdir($_dir, 0755))
{
print "Impossible de créer $_dir !";
die;
}
global $langs;
$dir=$_dir.'/'.$year;
if (! is_dir($dir))
{
$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);
}
}