diff --git a/htdocs/fourn/facture/fiche.php3 b/htdocs/fourn/facture/fiche.php3 index a8053788dd3..cf72fa78020 100644 --- a/htdocs/fourn/facture/fiche.php3 +++ b/htdocs/fourn/facture/fiche.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 @@ -28,47 +28,74 @@ $db = new Db(); $yn[1] = "oui"; $yn[0] = "non"; -if ($action == 'valid') { +if ($action == 'valid') +{ $sql = "UPDATE llx_facture_fourn set fk_statut = 1 WHERE rowid = $facid ;"; $result = $db->query( $sql); } -if ($action == 'payed') { +if ($action == 'payed') +{ $sql = "UPDATE llx_facture_fourn set paye = 1 WHERE rowid = $facid ;"; $result = $db->query( $sql); } +if ($action == 'update') +{ - - -if ($action == 'add') { - $datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear)); - - $tva = ($tva_taux * $amount) / 100 ; + $tva = ($HTTP_POST_VARS["tva_taux"] * $HTTP_POST_VARS["amount"]) / 100 ; $remise = 0; $total = $tva + $amount ; + $datefacture = $db->idate(mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"])); + + $sql = "UPDATE llx_facture_fourn set "; + $sql .= " libelle='".$HTTP_POST_VARS["libelle"]."'"; + $sql .= ", note='".$HTTP_POST_VARS["note"]."'"; + $sql .= ", datef = '$datefacture'"; + $sql .= ", amount=".$HTTP_POST_VARS["amount"]; + $sql .= ", total = $total"; + $sql .= ", tva = $tva"; + $sql .= " WHERE rowid = $facid ;"; + $result = $db->query( $sql); + +} + + + +if ($action == 'add') +{ + $datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear)); + $tva = 0; + $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 = ''; - + 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 !$sql
". $db->error(); + print "

Retour à la propal"; } - } 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 = ''; - + } /* * @@ -78,10 +105,10 @@ if ($action == 'add') { * */ -if ($action == 'create') { +if ($action == 'create') +{ print_titre("Emettre une facture"); - print "

"; print ''; print ""; @@ -91,21 +118,26 @@ if ($action == 'create') { $sql = "SELECT s.nom, s.prefix_comm, s.idp"; $sql .= " FROM societe as s WHERE s.fournisseur = 1 ORDER BY s.nom ASC"; - if ( $db->query($sql) ) { - $num = $db->num_rows(); - $i = 0; - while ($i < $num) { - $obj = $db->fetch_object($i); - print ''; - } else { - print '">'.$obj->nom.''; - } - $i++; + if ($socid == $obj->idp) + { + print '" SELECTED>'.$obj->nom.''; + } + else + { + print '">'.$obj->nom.''; + } + $i++; + } } - } print ''; print ""; @@ -133,23 +165,31 @@ if ($action == 'create') { print ""; $author = $GLOBALS["REMOTE_USER"]; print ""; @@ -169,15 +210,18 @@ if ($action == 'create') { print ""; print "
Société :Commentaires :
"; print "
Date :"; $cday = date("d", time()); print ""; $cmonth = date("n", time()); print ""; print "
"; -} else { +} +else +{ - if ($facid > 0) { + if ($facid > 0) + { - $sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.tva, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.note, f.libelle"; - $sql .= " FROM societe as s,llx_facture_fourn as f WHERE f.fk_soc = s.idp AND f.rowid = $facid"; + $sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.tva, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.note, f.libelle, f.rowid"; + $sql .= " FROM societe as s,llx_facture_fourn as f WHERE f.fk_soc = s.idp AND f.rowid = $facid"; - $result = $db->query( $sql); - + $result = $db->query( $sql); + if ($result) { $num = $db->num_rows(); if ($num) { @@ -187,6 +231,60 @@ if ($action == 'create') { } else { print $db->error(); } + + /* + * Edition + * + * + */ + if ($action == "edit") + { + + print "
rowid\" method=\"post\">"; + print ''; + + print ''; + print ""; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ""; + + print ""; + print ""; + print ""; + print "
Société :'.stripslashes($obj->socnom); + print 'Commentaires :
'; + print '
Numéro :
Libellé :
Montant HT :
TVA :
Date :"; + + print_date_select($obj->df); + + print "
Auteur :".$user->fullname."
"; + + } + + /* + * Affichage + * + * + */ + print ""; print ""; @@ -198,7 +296,10 @@ if ($action == 'create') { * Facture */ print "
"; - print ""; + print ""; + + + print "\n"; print ""; @@ -216,6 +317,9 @@ if ($action == 'create') { print ""; - print ""; + print "
Sociétésocidp\">$obj->socnom
Sociétésocidp\">$obj->socnom
Date".strftime("%A %d %B %Y",$obj->df)."
Libelle$obj->libelle"; + print nl2br(stripslashes($obj->note)); + + $_MONNAIE="euros"; /* @@ -264,31 +368,41 @@ if ($action == 'create') { } 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 ""; - } + if ($obj->statut == 0) + { + print ''; + } + else + { + print ""; + } + + + print ''; + + if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) + { + print ""; + } + else + { + print ""; + } + if ($obj->statut == 0) + { + print ""; + } + else + { + print ""; + } + + print "
['.translate("Delete").']-[Emettre un paiement]-[Classer 'Payée']-[Valider]-['.translate("Delete").']-[Editer][Classer 'Payée']-[Valider]-

"; /*