From 079c250a078b6efc2670863d94b1a1477e9022cd Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 25 Jun 2002 17:01:53 +0000 Subject: [PATCH] *** empty log message *** --- htdocs/fourn/facture/fiche.php3 | 486 ++++++++++++++++++++++++++++++++ 1 file changed, 486 insertions(+) create mode 100644 htdocs/fourn/facture/fiche.php3 diff --git a/htdocs/fourn/facture/fiche.php3 b/htdocs/fourn/facture/fiche.php3 new file mode 100644 index 00000000000..e007ce471d1 --- /dev/null +++ b/htdocs/fourn/facture/fiche.php3 @@ -0,0 +1,486 @@ + + * + * 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. + * + * $Id$ + * $Source$ + * + */ +require("./pre.inc.php3"); + +llxHeader(); + +$db = new Db(); + +$yn[1] = "oui"; +$yn[0] = "non"; + +if ($action == 'valid') { + $sql = "UPDATE llx_facture set fk_statut = 1 WHERE rowid = $facid ;"; + $result = $db->query( $sql); +} + +if ($action == 'payed') { + $sql = "UPDATE llx_facture set paye = 1 WHERE rowid = $facid ;"; + $result = $db->query( $sql); +} + +if ($action == 'delete') { + $sql = "DELETE FROM llx_facture WHERE rowid = $facid;"; + if ( $db->query( $sql) ) { + $sql = "DELETE FROM llx_fa_pr WHERE fk_facture = $facid;"; + if (! $db->query( $sql) ) { + print $db->error(); + } + } else { + print $db->error(); + } + $facid = 0 ; +} + + + +if ($action == 'add') { + $datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear)); + + $tva = ($tva_taux * $amount) / 100 ; + $remise = 0; + $total = $tva + $amount ; + + $sql = "INSERT INTO llx_facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, amount, remise, tva, total, fk_user_author) "; + $sql .= " VALUES ('$facnumber','$libelle', $socidp, now(), $datefacture,'$note', $amount, $remise, $tva, $total, $user->id);"; + $result = $db->query($sql); + + if ($result) { + $sql = "SELECT rowid, facnumber FROM llx_facture_fourn WHERE facnumber='$facnumber';"; + $result = $db->query($sql); + if ($result) { + $objfac = $db->fetch_object( 0); + $facid = $objfac->rowid; + $facnumber = $objfac->facnumber; + $action = ''; + + } + } else { + print "

Erreur : la facture n'a pas été créée, vérifier le numéro !$sql
". $db->error(); + print "

Retour à la propal"; + } + $facid = $facid; + $action = ''; + +} +/* + * + * Mode creation + * + * + * + */ + +if ($action == 'create') { + print_titre("Emettre une facture"); + + + print "

"; + print ''; + print ""; + + print ''; + print ""; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ""; + + $strmonth[1] = "Janvier"; $strmonth[2] = "Février"; $strmonth[3] = "Mars"; $strmonth[4] = "Avril"; + $strmonth[5] = "Mai"; $strmonth[6] = "Juin"; $strmonth[7] = "Juillet"; $strmonth[8] = "Août"; + $strmonth[9] = "Septembre"; $strmonth[10] = "Octobre"; + $strmonth[11] = "Novembre"; $strmonth[12] = "Décembre"; + + print ""; + $author = $GLOBALS["REMOTE_USER"]; + print ""; + + print ""; + print ""; + print ""; + print "
Société :Commentaires :
"; + print "
Numéro :
Libellé :
Montant HT :
TVA :
Date :"; + $cday = date("d", time()); + print ""; + $cmonth = date("n", time()); + print ""; + + print "
Auteur :".$user->fullname."
"; + +} else { + + if ($facid > 0) { + + $sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.author, f.note"; + $sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.rowid = $facid"; + + $result = $db->query( $sql); + + if ($result) { + $num = $db->num_rows(); + if ($num) { + $obj = $db->fetch_object( $i); + } + $db->free(); + } else { + print $db->error(); + } + + print ""; + print ""; + print ''; + print "\n"; + print ""; + print ""; + print ""; + print "
Facture : '.$obj->facnumber.'
socidp\">Autres factures de $obj->socnom
"; + /* + * Facture + */ + print ""; + print ""; + + print "\n"; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + + print ""; + print "
Sociétésocidp\">$obj->socnom
date".strftime("%A %d %B %Y",$obj->df)."
Auteur$obj->author
Statut$obj->statut
Paye".$yn[$obj->paye]."
Montant".price($obj->amount)."euros HT
TVA".tva($obj->amount)."euros
Total".price($obj->total)."euros TTC
"; + + print "
"; + + $_MONNAIE="euros"; + + /* + * Paiements + */ + $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid"; + $sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_facture = $facid AND p.fk_paiement = c.id"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows(); + $i = 0; $total = 0; + print "

Paiements"; + echo ''; + print ""; + print ""; + print ""; + print ""; + print "\n"; + + $var=True; + while ($i < $num) { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + print ""; + $total = $total + $objp->amount; + $i++; + } + print "\n"; + print "\n"; + + $resteapayer = $obj->total - $total; + + print ""; + print "\n"; + + print "
DateTypeMontant 
".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement".price($objp->amount)."$_MONNAIE
Total :".price($total)."$_MONNAIE
Facturé :".price($obj->total)."$_MONNAIE
Reste a payer :".price($resteapayer)."$_MONNAIE
"; + $db->free(); + } else { + print $db->error(); + } + + print "

Note : ".nl2br($obj->note)."
"; + + print "

"; + + if ($obj->statut == 0) { + print ""; + } else { + print ""; + } + if ($obj->statut == 1 && $resteapayer > 0) { + print ""; + } else { + print ""; + } + if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) { + print ""; + } else { + print ""; + } + if ($obj->statut == 0) { + print ""; + } else { + print ""; + } + print "
[Supprimer]-[Emettre un paiement]-[Classer 'Payée']-[Valider]Générer la facture

"; + + /* + * Documents générés + * + */ + print "


"; + print "
"; + print "Documents générés
"; + print ""; + + $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 ""; + + print "
Propale PDFfacnumber/$obj->facnumber.pdf\">$obj->facnumber.pdf
Propale Postscriptfacnumber/$obj->facnumber.ps\">$obj->facnumber.ps
(facnumber/\">liste...)
\n
"; + + /* + * 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
"; + } + + + /* + * Propales + */ + + $sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid"; + $sql .= " FROM llx_propal as p, llx_fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $facid"; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows(); + if ($num) { + $i = 0; $total = 0; + print "

Proposition(s) commerciale(s) associée(s)"; + print ''; + print ""; + print ""; + print ""; + print ""; + print "\n"; + + $var=True; + while ($i < $num) { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print "\n"; + print ''; + print ""; + $total = $total + $objp->price; + $i++; + } + print "\n"; + print "
NumDatePrix
propalid\">$objp->ref".strftime("%d %B %Y",$objp->dp)."'.price($objp->price).'
Total : ".price($total)." $_MONNAIE HT
"; + } + } else { + print $db->error(); + } + + } else { + /* + * + * Liste + * + * + */ + print_barre_liste("Factures",$page,$PHP_SELF); + + $sql = "SELECT s.nom,s.idp,f.facnumber,f.amount,".$db->pdate("f.datef")." as df,f.paye,f.rowid as facid"; + $sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp"; + + if ($socidp) { + $sql .= " AND s.idp = $socidp"; + } + + if ($month > 0) { + $sql .= " AND date_format(f.datef, '%m') = $month"; + } + if ($year > 0) { + $sql .= " AND date_format(f.datef, '%Y') = $year"; + } + + $sql .= " ORDER BY f.fk_statut, f.paye, f.datef DESC "; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows(); + + $i = 0; + print ""; + print ''; + print ""; + print ""; + print "\n"; + + if ($num > 0) { + $var=True; + while ($i < $num) { + $objp = $db->fetch_object( $i); + $var=!$var; + + if ($objp->paye && !$sep) { + print ""; + print ""; + + print ''; + print ""; + print "\n"; + $sep = 1 ; $j = 0; + $subtotal = 0; + } + + print ""; + print "\n"; + print "\n"; + + if ($objp->df > 0 ) { + print "\n"; + } else { + print "\n"; + } + + print "\n"; + + $total = $total + $objp->amount; + $subtotal = $subtotal + $objp->amount; + print "\n"; + + print "\n"; + $i++; + $j++; + + } + } + if ($i == 0) { $i=1; } if ($j == 0) { $j=1; } + print ""; + print ""; + + print ""; + print ""; + + print "
Numéro"; + print_liste_field_titre("Société",$PHP_SELF,"s.nom"); + print "DateMontantPayé
"; + print " Sous Total : ".price($total)."euros HT
Numéro"; + print_liste_field_titre("Société",$PHP_SELF,"s.nom"); + print "DateMontantPayé
facid\">$objp->facnumberidp\">$objp->nom"; + $y = strftime("%Y",$objp->df); + $m = strftime("%m",$objp->df); + + print strftime("%d",$objp->df)."\n"; + print " "; + print strftime("%B",$objp->df)."\n"; + print " "; + print strftime("%Y",$objp->df)."!!!".price($objp->amount)."".$yn[$objp->paye]."
$j factures Sous Total : ".price($subtotal)."euros HT
$i factures Total : ".price($total)."euros HT
"; + $db->free(); + } else { + print $db->error(); + } + + } + +} + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?>