* Copyright (C) 2004 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * * 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$ * */ /*! \file htdocs/fourn/facture/fiche.php \ingroup facture \brief Page des la fiche facture fournisseur \version $Revision$ */ require("./pre.inc.php"); require("./paiementfourn.class.php"); require("../../facturefourn.class.php"); $langs->load("bills"); $langs->load("companies"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } $html = new Form($db); $mesg=''; $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; if ($_GET["action"] == 'valid') { $facturefourn=new FactureFourn($db); $facturefourn->fetch($_GET["facid"]); $facturefourn->set_valid($user->id); } if ($_GET["action"] == 'payed') { $facturefourn=new FactureFourn($db); $facturefourn->fetch($_GET["facid"]); $facturefourn->set_payed($user->id); } 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 ($_POST["action"] == 'modif_libelle') { $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set libelle = '$form_libelle' WHERE rowid = ".$_GET["facid"]." ;"; $result = $db->query( $sql); } if ($_POST["action"] == 'update') { $datefacture = $db->idate(mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"])); $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn set "; $sql .= " facnumber='".trim($_POST["facnumber"])."'"; $sql .= ", libelle='".trim($_POST["libelle"])."'"; $sql .= ", note='".$_POST["note"]."'"; $sql .= ", datef = '$datefacture'"; $sql .= " WHERE rowid = ".$_GET['facid']." ;"; $result = $db->query( $sql); } if ($_POST["action"] == 'add') { if ($_POST["facnumber"]) { $datefacture = $db->idate(mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"])); $tva = 0; $tva = ($_POST["tva_taux"] * $_POST["amount"]) / 100 ; $remise = 0; $total = $tva + $_POST["amount"] ; $db->begin(); // Creation facture $facfou = new FactureFourn($db); $facfou->number = $_POST["facnumber"]; $facfou->socid = $_POST["socidp"]; $facfou->libelle = $_POST["libelle"]; $facfou->date = $datefacture; $facfou->note = $_POST["note"]; $facid = $facfou->create($user); // Ajout des lignes de factures if ($facid > 0) { for ($i = 1 ; $i < 9 ; $i++) { $label = "label$i"; $amount = "amount$i"; $tauxtva = "tauxtva$i"; $qty = "qty$i"; if (strlen($_POST["$label"]) > 0 && $_POST["$amount"] > 0) { $atleastoneline=1; $facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1); } } $db->commit(); } else { $db->rollback(); } header("Location: fiche.php?facid=$facid"); } else { $mesg="
Erreur: Un numéro de facture fournisseur est obligatoire.
"; } } if ($_GET["action"] == 'del_ligne') { $facfou = new FactureFourn($db,"",$_GET["facid"]); $facfou->deleteline($_GET["ligne_id"]); $_GET["action"] = "edit"; } if ($_GET["action"] == 'add_ligne') { $facfou = new FactureFourn($db,"", $_GET["facid"]); $facfou->addline($_POST["label"], $_POST["amount"], $_POST["tauxtva"], $_POST["qty"]); $_GET["action"] = "edit"; } /* * */ llxHeader(); if ($mesg) { print "
$mesg
"; } /* * * Fiche facture en mode creation * */ if ($_GET["action"] == 'create' or $_GET["action"] == 'copy') { if ($_GET["action"] == 'copy') { $fac_ori = new FactureFourn($db); $fac_ori->fetch($_GET["facid"]); } print_titre("Saisir une facture fournisseur"); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($_GET["action"] == 'copy') { print ''; } else { print ''; } print ''; print ''; print "
Société'.$langs->trans("Comments").'
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Label").'
'.$langs->trans("Date").''; $html->select_date(); print '
'.$langs->trans("Author").''.$user->fullname.'

"; print ''; print ''; for ($i = 1 ; $i < 9 ; $i++) { if ($_GET["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 "
 '.$langs->trans("Label").'P.U. HT'.$langs->trans("Qty").''.$langs->trans("VATRate").'
Ligne '.$i.''; $html->select_tva("tauxtva".$i); print '
"; print '

'; print "
"; } else { /* * Fiche facture en mode edition * */ if ($_GET["facid"] > 0) { $fac = new FactureFourn($db); $fac->fetch($_GET["facid"]); if ($_GET["action"] == "edit") { print_titre($langs->trans("Bill").' : '.$fac->ref); print '
'; 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 ""; print "
'.$langs->trans("Company").''.stripslashes($fac->socnom).''.$langs->trans("Comments").'
'.$langs->trans("Ref").''; print ''; print '
'.$langs->trans("Label").''; print '
'.$langs->trans("AmountTTC").''.price($fac->total_ht).'
'.$langs->trans("Date").''; print_date_select($fac->datep); print "
".$langs->trans("Author")."$authorfullname
'.$langs->trans("Status").''.$fac->LibStatut($fac->paye,$fac->statut)."
trans("Save")."\">
"; print "
"; /* * Lignes * */ print "

id&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 "
'.$langs->trans("Label").'P.U. HT'.$langs->trans("Qty").''.$langs->trans("TotalHT").''.$langs->trans("VATRate").''.$langs->trans("VAT").''.$langs->trans("TotalTTC").' 
'.$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 { /* * Fiche facture en mode edition * */ $h=0; $head[$h][0] = "fiche.php?facid=".$fac->id; $head[$h][1] = $langs->trans("Bill").' : '.$fac->ref; $hselected = $h; $h++; dolibarr_fiche_head($head, $hselected); 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 '"; print "".'"; if (strlen($fac->note)) { print ''; } print "
".$langs->trans("Company")."socidp\">$fac->socnomsocidp\">Autres factures
'.$langs->trans("Date")."".dolibarr_print_date($fac->datep,"%A %d %B %Y")."
'.$langs->trans("Label").''; print $fac->libelle; print "
".$langs->trans("Author")."$authorfullname
'.$langs->trans("Status").''.$fac->LibStatut($fac->paye,$fac->statut)."
 '.$langs->trans("TotalHT").''.price($fac->total_ht)."'.$langs->trans("VAT").''.price($fac->total_tva)."
 '.$langs->trans("TotalTTC").''.price($fac->total_ttc)."
'.$langs->trans("Comments").''; print nl2br(stripslashes($fac->note)); print '
"; print "
"; /* * 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 ''; print ''; if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) { $tdsup=' colspan="2"'; } print " "; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object(); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) { print ''; } print ""; $total = $total + $objp->amount; $i++; } print "".$conf->monnaie."\n"; if ($fac->statut > 0) { $resteapayer = abs($fac->total_ttc - $total); print ""; print '".$conf->monnaie.""; print "\n"; } print "
'.$langs->trans("Paiements").'
'.$langs->trans("Date").''.$langs->trans("Type").'Montant
".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement".price($objp->amount)."".$conf->monnaie."'; print ''; print img_delete(); print '
Total :".price($total)."
Reste à payer :'.price($resteapayer)."
"; $db->free(); } else { print $db->error(); } print "
"; /* * Lignes * */ print '

'; print ''; print ''; print ''; print ''; $var=1; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { $var=!$var; print "".'"; print '"; print '"; print '"; print '"; print '"; print '"; print ''; } print "
'.$langs->trans("Label").'P.U. HTQantitéTotal HTTaux TVATVA'.$langs->trans("TotalTTC").'
'.$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 "\n"; } /* * Barre de commande * * */ print "

\n"; if ($fac->statut == 0 && $user->societe_id == 0) { if ($_GET["action"] != "edit") { print ''.$langs->trans("Delete").''; } } elseif ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) { print ''.$langs->trans("DoPaiement").''; } if ($fac->statut == 0 && $user->societe_id == 0) { if ($_GET["action"] == "edit") { print ''.$langs->trans("Cancel").''; } else { print ''.$langs->trans('Edit').''; } } if ($fac->statut == 1 && price($resteapayer) <= 0 && $fac->paye == 0 && $user->societe_id == 0) { print "id&action=payed\">".$langs->trans('ClassifyPayed').""; } if ($user->societe_id == 0) { if ($fac->statut == 0) { if ($_GET["action"] <> "edit") print "id&action=valid\">".$langs->trans('Valid').""; } else { print "id&action=copy&socid=$fac->socidp\">".$langs->trans('Copy').""; } } print "
"; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>