* Copyright (C) 2004 Laurent Destailleur * * 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.php"); require("./paiementfourn.class.php"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } $html = new Form($db); if ($action == 'valid') { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set fk_statut = 1 WHERE rowid = $facid ;"; $result = $db->query( $sql); } if ($action == 'payed') { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set paye = 1 WHERE rowid = $facid ;"; $result = $db->query( $sql); } if($_GET["action"] == 'deletepaiement') { $facfou = new FactureFourn($db); $facfou->fetch($_GET["facid"]); if ($facfou->statut == 1 && $facfou->paye == 0 && $user->societe_id == 0) { $paiementfourn = new PaiementFourn($db); $paiementfourn->delete($_GET["paiement_id"]); } } if ($HTTP_POST_VARS["action"] == 'modif_libelle') { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set libelle = '$form_libelle' WHERE rowid = $facid ;"; $result = $db->query( $sql); } if ($action == 'update') { $datefacture = $db->idate(mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"])); $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set "; $sql .= " facnumber='".trim($HTTP_POST_VARS["facnumber"])."'"; $sql .= ", libelle='".trim($HTTP_POST_VARS["libelle"])."'"; $sql .= ", note='".$HTTP_POST_VARS["note"]."'"; $sql .= ", datef = '$datefacture'"; $sql .= " WHERE rowid = $facid ;"; $result = $db->query( $sql); } if ($action == 'add') { $datefacture = $db->idate(mktime(12, 0, 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"])); $tva = 0; $tva = ($tva_taux * $amount) / 100 ; $remise = 0; $total = $tva + $amount ; $facfou = new FactureFourn($db); $facfou->number = $HTTP_POST_VARS["facnumber"]; $facfou->socid = $HTTP_POST_VARS["socidp"]; $facfou->libelle = $HTTP_POST_VARS["libelle"]; $facfou->date = $datefacture; $facfou->note = $HTTP_POST_VARS["note"]; for ($i = 1 ; $i < 9 ; $i++) { $label = "label$i"; $amount = "amount$i"; $tauxtva = "tauxtva$i"; $qty = "qty$i"; if (strlen($$label)) { // print "Ajour ligne $i " . $$label . " " . $$amount . " " . $$tauxtva ; // DEBUG $facfou->add_ligne($$label, $$amount, $$tauxtva, $$qty); } } $facid = $facfou->create($user); } if ($action == 'del_ligne') { $facfou = new FactureFourn($db,"",$facid); if ($facfou->delete_ligne($ligne_id)) { $action="edit"; } } if ($action == 'add_ligne') { $facfou = new FactureFourn($db,"", $facid); $facfou->add_ligne($HTTP_POST_VARS["label"], $HTTP_POST_VARS["amount"], $HTTP_POST_VARS["tauxtva"], $HTTP_POST_VARS["qty"], 1); $action="edit"; } /* * */ llxHeader(); /* * * Mode creation * */ if ($action == 'create' or $action == 'copy') { if ($action == 'copy') { $fac_ori = new FactureFourn($db); $fac_ori->fetch($facid); } print_titre("Saisir une facture"); print '
'; print ''; print ''; print ''; print ''; print ""; print ''; print ''; if ($action == 'copy') { print ''; } else { print ''; } print "".''; print ''; print "
Société :Commentaires :
Numéro :
Libellé :
Libellé :
Date :'; $html->select_date(); print '
Auteur :'.$user->fullname.'

"; print ''; print "".''; for ($i = 1 ; $i < 9 ; $i++) { if ($action == 'copy') { $value_label = $fac_ori->lignes[$i-1][0]; $value_pu = $fac_ori->lignes[$i-1][1]; $value_qty = $fac_ori->lignes[$i-1][3]; } else { $value_qty = "1"; } print ''; print ''; print ''; print ''; } print "
 LibelléP.U.QtyTx TVA
Ligne '.$i.' :'; $html->select_tva("tauxtva".$i); print '
"; print '

'; print "
"; } else { if ($facid > 0) { $fac = new FactureFourn($db); $fac->fetch($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 ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn 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_titre ('Facture : '.$obj->facnumber); /* * Edition * * */ if ($action == "edit") { print "
rowid\" method=\"post\">"; print ''; print ''; print ""; print ''; print ''; print "".''; print ''; print "".''; print "".''; print ''; print ""; $authorfullname=" "; if ($fac->author) { $author = new User($db, $fac->author); $author->fetch(''); $authorfullname=$author->fullname; } print ""; print ""; print "
Société :'.stripslashes($obj->socnom); print 'Commentaires :
Numéro :'; print ''; print '
Libellé :'; print '
Montant HT :'.price($fac->total_ht).'
Date :"; print_date_select($obj->df); print "
Auteur :$authorfullname
"; print "
"; /* * Lignes * */ print "

rowid&action=add_ligne\" method=\"post\">"; print ''; print ''; print ''; print ''; print ''; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { print "".'"; print '"; print '"; print '"; print '"; print '"; print '"; print ''; print ''; } /* Nouvelle ligne */ print ""; print ''; print ''; print ''; print ''; print ''; print "
LibelléP.U. HTQtyTotal HTTaux TVATVATotal TTC 
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]."'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."'; print ''.img_delete().'
'; print ''; print ''; print ''; print ''; print ''; print '-'; $html->select_tva("tauxtva"); print ''; print ' '; print '
"; print "
"; } else { /* * Affichage * * */ print ""; print '"; print "
'; /* * Facture */ print ''; print ""; print "\n"; print ""; print "\n"; print ""; $authorfullname=" "; if ($fac->author) { $author = new User($db, $fac->author); $author->fetch(''); $authorfullname=$author->fullname; } print ""; print "".'"; print '"; print "".'"; if (strlen($obj->note)) { print "".''; } print "
Sociétésocidp\">$obj->socnomsocidp\">Autres factures
Date".strftime("%A %d %B %Y",$obj->df)."
Libellé"; print $obj->libelle; print "
Auteur$authorfullname
 Total HT'.price($fac->total_ht)."TVA'.price($fac->total_tva)."
 Total TTC'.price($fac->total_ttc)."
Commentaires'; print nl2br(stripslashes($obj->note)); print '
"; 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 ".MAIN_DB_PREFIX."paiementfourn as p, ".MAIN_DB_PREFIX."c_paiement as c "; $sql .= " WHERE p.fk_facture_fourn = ".$fac->id." AND p.fk_paiement = c.id"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $total = 0; echo ''; print ""; print ""; print ""; if ($obj->statut == 1 && $obj->paye == 0 && $user->societe_id == 0) { $tdsup=' colspan="2"'; } print " "; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; if ($obj->statut == 1 && $obj->paye == 0 && $user->societe_id == 0) { print ''; } print ""; $total = $total + $objp->amount; $i++; } print "$_MONNAIE\n"; $resteapayer = abs($fac->total_ttc - $total); print ""; print '$_MONNAIE"; print "\n"; print "
DateTypeMontant
".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement".price($objp->amount)."$_MONNAIE'; print ''; print img_delete(); print '
Total :".price($total)."
Reste a payer :'.price($resteapayer)."
"; $db->free(); } else { print $db->error(); } print "
"; /* * Lignes * */ print '

'; print ''; print ''; print ''; print ''; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { print "".'"; print '"; print '"; print '"; print '"; print '"; print '"; print ''; } print "
LibelléP.U. HTQantitéTotal HTTaux TVATVATotal TTC
'.$fac->lignes[$i][0]."'.price($fac->lignes[$i][1])."'.$fac->lignes[$i][3]."'.price($fac->lignes[$i][4])."'.$fac->lignes[$i][2]." %'.price($fac->lignes[$i][5])."'.price($fac->lignes[$i][6])."
"; } /* * Barre de commande * * */ print "

\n"; if ($obj->statut == 0 && $user->societe_id == 0) { print 'Supprimer'; } elseif ($obj->statut == 1 && $obj->paye == 0 && $user->societe_id == 0) { print 'Emmettre un paiement'; } if ($obj->statut == 0 && $user->societe_id == 0) { if ($action == "edit") { print 'Annuler'; } else { print 'Editer'; } } if ($obj->statut == 1 && price($resteapayer) <= 0 && $obj->paye == 0 && $user->societe_id == 0) { print "Classer 'Payée'"; } if ($user->societe_id == 0) { if ($obj->statut == 0) { print "Valider"; } else { print "socidp\">Copier"; } } print "
"; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>