dolibarr/htdocs/compta/export/ComptaJournalVente.class.php

256 lines
6.4 KiB
PHP
Raw Normal View History

2005-03-23 14:59:47 +01:00
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*
* $Id$
* $Source$
*
*/
require_once(DOL_DOCUMENT_ROOT.'/compta/export/ComptaJournalPdf.class.php');
class ComptaJournalVente {
function ComptaJournalVente ($db=0)
{
$this->db = $db;
}
2005-03-31 12:11:08 +02:00
function GeneratePdf($user, $excid, $excref)
2005-03-23 14:59:47 +01:00
{
$date = strftime("%Y%m",time());
$dir = DOL_DATA_ROOT."/compta/export/";
2005-03-31 12:11:08 +02:00
$file = $dir . "JournalVente".$excref . ".pdf";
2005-03-23 14:59:47 +01:00
if (file_exists($dir))
{
$pdf = new ComptaJournalPdf('P','mm','A4');
$pdf->AliasNbPages();
$pdf->Open();
$pdf->AddPage();
$this->tab_top = 90;
$this->tab_height = 90;
$pdf->SetTitle("Journal des ventes");
$pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($user->fullname);
$pdf->SetMargins(10, 10, 10);
$pdf->SetAutoPageBreak(1,10);
/*
*
*/
$pdf->SetFillColor(220,220,220);
$pdf->SetFont('Arial','', 9);
$pdf->SetXY (10, 10 );
$nexY = $pdf->GetY();
$sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as dp";
$sql .= " , f.total_ttc as amount, f.tva ";
$sql .= " ,s.nom, s.code_compta";
$sql .= " , l.price, l.tva_taux";
$sql .= " , c.numero, f.increment";
$sql .= " , l.rowid as lrowid";
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c";
$sql .= " WHERE f.rowid = l.fk_facture ";
$sql .= " AND s.idp = f.fk_soc";
$sql .= " AND f.fk_statut = 1 ";
$sql .= " AND l.fk_code_ventilation <> 0 ";
2005-03-23 16:38:33 +01:00
$sql .= " AND l.fk_export_compta <> 0";
2005-03-23 14:59:47 +01:00
$sql .= " AND c.rowid = l.fk_code_ventilation";
2005-03-31 12:11:08 +02:00
$sql .= " AND l.fk_export_compta = ".$excid;
2005-03-23 14:59:47 +01:00
2005-03-23 16:38:33 +01:00
$sql .= " ORDER BY date_format(f.datef,'%Y%m%d') ASC, f.rowid, l.rowid";
2005-03-23 14:59:47 +01:00
$oldate = '';
2005-03-23 16:38:33 +01:00
$oldfac = '';
$resql = $this->db->query($sql);
if ($resql)
2005-03-23 14:59:47 +01:00
{
2005-03-23 16:38:33 +01:00
$num = $this->db->num_rows($resql);
2005-03-23 14:59:47 +01:00
$i = 0;
$var = True;
2005-04-11 18:13:03 +02:00
$journ = 'VI';
2005-03-23 14:59:47 +01:00
$hligne = 5;
2005-03-23 16:38:33 +01:00
$wc = array(0,14,6,16,16,90,16,12,4,16);
2005-03-23 14:59:47 +01:00
while ($i < $num)
{
2005-03-23 16:38:33 +01:00
$obj = $this->db->fetch_object($resql);
2005-03-23 14:59:47 +01:00
if ($oldate <> strftime("%d%m%Y",$obj->dp))
{
$journal = "Journal $journ du ".strftime('%A, %e %B %G',$obj->dp);
$total_credit = 0 ;
$total_debit = 0 ;
$pdf->SetFont('Arial','B',10);
$pdf->cell(10,$hligne,"$journal");
$pdf->ln();
$pdf->SetFont('Arial','',9);
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[1],$hligne,'Date');
$pdf->cell($wc[2],$hligne,'');
$pdf->cell($wc[3],$hligne,'Compte');
$pdf->cell($wc[4],$hligne,'Tiers');
$pdf->cell($wc[5],$hligne,'Libell<6C>');
$pdf->cell($wc[6],$hligne,'Facture');
$pdf->cell($wc[7],$hligne,'Montant',0,0,'R');
$pdf->cell($wc[8],$hligne,'');
$pdf->cell($wc[9],$hligne,'Echeance',0,0,'R');
2005-03-23 14:59:47 +01:00
$pdf->ln();
$oldate = strftime("%d%m%Y",$obj->dp);
}
/*
*
*/
$socnom = $obj->nom;
$libelle = "Facture";
2005-03-23 16:38:33 +01:00
$amount = abs($obj->amount);
$price = abs(price($obj->price));
$tva = abs($obj->tva);
2005-03-23 14:59:47 +01:00
$facnumber = $obj->facnumber;
if (strlen(trim($obj->increment)) > 0)
{
$facnumber = $obj->increment;
}
2005-03-23 14:59:47 +01:00
if (strlen($obj->nom) > 31)
{
$socnom = substr($obj->nom, 0 , 31);
}
$pdf->SetFont('Arial','',9);
if ($obj->amount >= 0)
{
2005-03-23 16:38:33 +01:00
$d = "D";
$c = "C";
2005-03-31 12:11:08 +02:00
$credit = '';
$debit = $amount;
$total_debit = $total_debit + $debit;
$grand_total_debit = $grand_total_debit + $debit;
2005-03-23 14:59:47 +01:00
}
else
{
2005-03-23 16:38:33 +01:00
$d = "C";
$c = "D";
2005-03-31 12:11:08 +02:00
$credit = $amount;
$debit = '';
$total_credit = $total_credit + $credit;
$grand_total_credit = $grand_total_credit + $credit;
2005-03-23 14:59:47 +01:00
}
2005-03-23 16:38:33 +01:00
if ($oldfac <> $obj->facid)
2005-03-23 14:59:47 +01:00
{
2005-03-23 16:38:33 +01:00
$oldfac = $obj->facid;
$pdf->cell($wc[1],$hligne,strftime('%d%m%y',$obj->dp));
2005-04-11 18:13:03 +02:00
$pdf->cell($wc[2],$hligne,'VI');
2005-04-11 18:13:25 +02:00
$pdf->cell($wc[3],$hligne,'41100000');
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[4],$hligne,$obj->code_compta);
$pdf->cell($wc[5],$hligne,$socnom .' '.$libelle);
$pdf->cell($wc[6],$hligne,$facnumber);
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[7],$hligne,$amount,0,0,'R');
$pdf->cell($wc[8],$hligne,$d);
$pdf->cell($wc[9],$hligne,strftime('%d%m%y',$obj->dp),0,0,'R');
$pdf->ln();
$pdf->cell($wc[1],$hligne,strftime('%d%m%y',$obj->dp));
2005-04-11 18:13:03 +02:00
$pdf->cell($wc[2],$hligne,'VI');
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[3],$hligne,'4457119');
$pdf->cell($wc[4],$hligne,'');
$pdf->cell($wc[5],$hligne,$socnom .' '.$libelle);
$pdf->cell($wc[6],$hligne,$facnumber);
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[7],$hligne,$tva,0,0,'R');
$pdf->cell($wc[8],$hligne,$c);
$pdf->cell($wc[9],$hligne,strftime('%d%m%y',$obj->dp),0,0,'R');
$pdf->ln();
2005-03-23 14:59:47 +01:00
}
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[1],$hligne,strftime('%d%m%y',$obj->dp));
2005-04-11 18:13:03 +02:00
$pdf->cell($wc[2],$hligne,'VI');
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[3],$hligne,$obj->numero);
$pdf->cell($wc[4],$hligne,'');
$pdf->cell($wc[5],$hligne,$socnom .' '.$libelle);
$pdf->cell($wc[6],$hligne,$facnumber);
2005-03-23 16:38:33 +01:00
$pdf->cell($wc[7],$hligne,$price,0,0,'R');
$pdf->cell($wc[8],$hligne,$c);
$pdf->cell($wc[9],$hligne,strftime('%d%m%y',$obj->dp),0,0,'R');
2005-03-23 14:59:47 +01:00
$pdf->ln();
$i++;
}
/*
*
*
*/
$pdf->Close();
$pdf->Output($file);
2005-03-23 16:38:33 +01:00
$result = 0;
2005-03-23 14:59:47 +01:00
}
else
{
2005-03-23 16:38:33 +01:00
$result -1;
2005-03-23 14:59:47 +01:00
}
}
else
{
2005-03-23 16:38:33 +01:00
$result = -2;
2005-03-23 14:59:47 +01:00
}
2005-03-23 16:38:33 +01:00
return $result;
2005-03-23 14:59:47 +01:00
}
/*
*
*
*/
}
?>