From aa95b50ab0071cc1dc9b896aec30c7f9d0eb0758 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Sat, 1 Feb 2003 19:45:45 +0000 Subject: [PATCH] Gestion des lignes de factures --- htdocs/compta/facture.php3 | 149 ++++++++++++++++++++++++++++++------- htdocs/facture.class.php3 | 147 ++++++++++++++++++++++++++++-------- 2 files changed, 238 insertions(+), 58 deletions(-) diff --git a/htdocs/compta/facture.php3 b/htdocs/compta/facture.php3 index bda0481f607..798ae1c6f3e 100644 --- a/htdocs/compta/facture.php3 +++ b/htdocs/compta/facture.php3 @@ -1,5 +1,5 @@ +/* Copyright (C) 2002-2003 Rodolphe Quiedeville * * 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 @@ -41,6 +41,19 @@ if ($action == 'payed') $result = $fac->set_payed($facid); } +if ($action == 'addligne') +{ + $fac = new Facture($db); + $result = $fac->addline($facid,$HTTP_POST_VARS["desc"],$HTTP_POST_VARS["pu"],$HTTP_POST_VARS["qty"]); +} + +if ($action == 'deleteline') +{ + $fac = new Facture($db); + $fac->id = $facid; + $result = $fac->deleteline($rowid); +} + if ($action == 'delete') { $fac = new Facture($db); @@ -149,8 +162,11 @@ if ($action == 'create') print ''; - print ""; + print ""; + print ''; + if ($propalid) { $amount = ($obj->price - $obj->remise); @@ -222,10 +238,11 @@ if ($action == 'create') } print ""; print ""; - - print ''; - print ''; + + + print ''; + print ''; + print ''; + print ''; + print ''; + print "
Société :$obj->nom
Société :$obj->nom'; + print '
Numéro :
Commentaires :
'; - print '
Désignation
"; + print ""; } + /* * Fin Ajout ligne * */ + print "

"; + if ($obj->statut == 0) { print ""; @@ -416,16 +494,31 @@ else print "Documents générés
"; print "
[Supprimer]
"; - $file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/facture/$obj->facnumber/$obj->facnumber.pdf"; - if (file_exists($file)) { - print ""; - } - $file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/facture/$obj->facnumber/$obj->facnumber.ps"; - if (file_exists($file)) { - print ""; - print ""; - } - print ""; + $file = $conf->facture->outputdir . "/" . $obj->facnumber . "/" . $obj->facnumber . ".pdf"; + + + if (file_exists($file)) + { + print ""; + print ''; + print ''; + print ''; + print ''; + } + + $file = $conf->facture->outputdir . "/" . $obj->facnumber . "/" . $obj->facnumber . ".ps"; + + if (file_exists($file)) + { + print ""; + print ''; + print ''; + print ''; + print ''; + + + } + print ''; print "
Propale PDFfacnumber/$obj->facnumber.pdf\">$obj->facnumber.pdf
Propale Postscriptfacnumber/$obj->facnumber.ps\">$obj->facnumber.ps
(facnumber/\">liste...)
Propale PDFfacnumber."/".$obj->facnumber.'.pdf">'.$obj->facnumber.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Propale Postscriptfacnumber."/".$obj->facnumber.'.ps">'.$obj->facnumber.'.ps'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
(liste...)
\n"; @@ -433,15 +526,17 @@ else * Generation de la facture * */ - if ($action == 'pdf') { - print "


Génération de la facture
"; - $command = "export DBI_DSN=\"dbi:mysql:dbname=lolixfr\" "; - $command .= " ; ../../scripts/facture-tex.pl --html -vv --facture=$facid --pdf --gljroot=" . $GLOBALS["GLJ_ROOT"] ; - - $output = system($command); - print "

command :
$command
"; - print "

output :
$output
"; - } + if ($action == 'pdf') + { + print "


Génération de la facture
"; + $command = "export DBI_DSN=\"dbi:mysql:dbname=".$conf->db->name."\" "; + $command .= " ; ./tex-facture.pl --html -vv --facture=$facid --pdf --output=".$conf->facture->outputdir; + $command .= " --templates=".$conf->facture->templatesdir; + + $output = system($command); + print "

command :
$command
"; + //print "

output :
$output
"; + } /* diff --git a/htdocs/facture.class.php3 b/htdocs/facture.class.php3 index c9bfb018d25..4f5c09632c6 100644 --- a/htdocs/facture.class.php3 +++ b/htdocs/facture.class.php3 @@ -1,5 +1,5 @@ +/* Copyright (C) 2002-2003 Rodolphe Quiedeville * * 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 @@ -106,41 +106,50 @@ class Facture { * * */ - Function fetch($rowid) { + Function fetch($rowid) + { - $sql = "SELECT ref,price,remise,".$this->db->pdate(datep)."as dp FROM llx_facture WHERE rowid=$rowid;"; - - if ($this->db->query($sql) ) { - if ($this->db->num_rows()) { - $obj = $this->db->fetch_object(0); - - $this->id = $rowid; - $this->datep = $obj->dp; - $this->ref = $obj->ref; - $this->price = $obj->price; - $this->remise = $obj->remise; - - $this->db->free(); - } - } else { - print $this->db->error(); - } - } + $sql = "SELECT ref,price,remise,".$this->db->pdate(datep)."as dp FROM llx_facture WHERE rowid=$rowid;"; + + if ($this->db->query($sql) ) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object(0); + + $this->id = $rowid; + $this->datep = $obj->dp; + $this->ref = $obj->ref; + $this->price = $obj->price; + $this->remise = $obj->remise; + + $this->db->free(); + } + } + else + { + print $this->db->error(); + } + } /* * * * */ - Function valid($userid) { - $sql = "UPDATE llx_facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid"; - $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; - - if ($this->db->query($sql) ) { - return 1; - } else { - print $this->db->error() . ' in ' . $sql; + Function valid($userid, $dir) + { + $sql = "UPDATE llx_facture SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid"; + $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; + + if ($this->db->query($sql) ) + { + return 1; + } + else + { + print $this->db->error() . ' in ' . $sql; + } } - } /* * Suppression de la facture @@ -159,7 +168,18 @@ class Facture { if ($this->db->query( $sql) ) { - return 1; + + $sql = "DELETE FROM llx_facturedet WHERE fk_facture = $rowid;"; + + if ($this->db->query( $sql) ) + { + return 1; + } + else + { + print "Err : ".$this->db->error(); + return 0; + } } else { @@ -189,8 +209,73 @@ class Facture { Function set_valid($rowid, $userid) { + global $conf; + $sql = "UPDATE llx_facture set fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid ;"; $result = $this->db->query( $sql); + + $dir = $conf->facture->outputdir . "/" . $rowid; + + if (! is_dir ("$dir")) + { + if (! mkdir ("$dir")) + { + print $dir; + } + } + } + /* + * + * + */ + Function addline($facid, $desc, $pu, $qty) + { + global $conf; + + $sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty) VALUES ($facid, '$desc', $pu, $qty) ;"; + $result = $this->db->query( $sql); + + $this->updateprice($facid); + } + /* + * + * + */ + Function deleteline($rowid) + { + $sql = "DELETE FROM llx_facturedet WHERE rowid = $rowid;"; + $result = $this->db->query( $sql); + + $this->updateprice($this->id); + } + /* + * + * + */ + Function updateprice($facid) + { + + $sql = "SELECT sum(price*qty) FROM llx_facturedet WHERE fk_facture = $facid;"; + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows() ) + { + $row = $this->db->fetch_row(); + $totalht = $row[0]; + } + + $tva = tva($totalht); + $total = $totalht + $tva; + + $sql = "UPDATE llx_facture SET amount = $totalht, tva=$tva, total=$total"; + $sql .= " WHERE rowid = $facid ;"; + + $result = $this->db->query($sql); + + } } /* @@ -211,5 +296,5 @@ class Facture { print "

command : $command
"; } -} +} ?>