* 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$ * */ /*! \file htdocs/compta/facture/fiche-rec.php \ingroup facture \brief Page d'affichage d'une facture récurrent \version $Revision$ */ require("./pre.inc.php"); require("./facture-rec.class.php"); $user->getrights('facture'); if (!$user->rights->facture->lire) accessforbidden(); require("../../project.class.php"); llxHeader('','Facture récurrente','ch-facture.html#s-fac-facture-rec'); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * */ if ($_POST["action"] == 'add') { $facturerec = new FactureRec($db, $facid); $facturerec->titre = $_POST["titre"]; if ($facturerec->create($user) > 0) { $facid = $facturerec->id; $action = ''; } else { $action = "create"; } } /* * */ if ($action == 'delete' && $user->rights->facture->supprimer) { $fac = new FactureRec($db); $fac->delete($facid); $facid = 0 ; } /* * */ $html = new Form($db); /********************************************************************* * * Mode creation * * * ************************************************************************/ if ($_GET["action"] == 'create') { print_titre("Créer une facture récurrente"); $facture = new Facture($db); if ($facture->fetch($_GET["facid"]) > 0) { print '
'; print ''; print ''; print ''; $facture->fetch_client(); print ''; print ''; print ''; print ''; print ""; print ""; print "
'.$langs->trans("Customer").' :'.$facture->client->nom.''.$langs->trans("Comment").'
'.$langs->trans("Title").' :'; print '
".$langs->trans("Author")." :".$user->fullname."
Conditions de réglement :"; print $facture->cond_reglement; print "
Projet :"; if ($facture->projetid > 0) { $proj = new Project($db); $proj->fetch($facture->projetid); print $proj->title; } print "
"; print_titre('Services/Produits'); print ''; /* * Lignes de factures * */ print ''; if ($flag_different_price) { print ''; } print ''; print "\n"; print "
'; $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l WHERE l.fk_facture = $facture->id ORDER BY l.rowid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $total = 0; echo ''; if ($num) { print ""; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=True; while ($i < $num) { $objp = $db->fetch_object(); if ($objp->fk_product > 0) { $product = New Product($db); $product->fetch($objp->fk_product); } $var=!$var; print ""; if ($objp->fk_product) { print ''; } else { print "\n"; } print ''; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; if ($objp->fk_product > 0 && $objp->subprice <> $product->price) { print '\n"; $flag_different_price++; } else { print ''; } print ""; $i++; } $db->free(); } else { print $db->error(); } print "
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'N.P.
'.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->tva_taux.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."'.price($product->price)." 
"; print '
'; print ''; print '
\n"; } else { print "Erreur facture $facture->id inexistante"; } } else /* *************************************************************************** */ /* */ /* */ /* */ /* *************************************************************************** */ { if ($facid > 0) { $fac = New FactureRec($db,0); if ( $fac->fetch($facid, $user->societe_id) > 0) { $soc = new Societe($db, $fac->socidp); $soc->fetch($fac->socidp); $author = new User($db); $author->id = $fac->user_author; $author->fetch(); print_titre("Facture : ".$fac->titre); /* * Facture */ print ''; print ""; print "'; print ""; print ""; if ($fac->remise_percent > 0) { print '"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($fac->note) { print '"; } print "
Client"; print ''.$soc->nom.'Conditions de réglement : " . $fac->cond_reglement ."
".$langs->trans("Author")."$author->fullname'; } else { print ''; } print "
'.$langs->trans("Amount").''.price($fac->total_ht).''.$conf->monnaie.' HT
'.$langs->trans("VAT").''.price($fac->total_tva).''.$conf->monnaie.'
'.$langs->trans("TotalTTC").''.price($fac->total_ttc).''.$conf->monnaie.'
Note : '.nl2br($fac->note)."

"; /* * Lignes * */ print_titre($langs->trans("Products")); print ''; print ''; print ''; $num = sizeof($fac->lignes); $i = 0; $var=True; while ($i < $num) { $var=!$var; if ($fac->lignes[$i]->produit_id > 0) { $prod = New Product($db); $prod->fetch($fac->lignes[$i]->produit_id); print "'; print ''; } else { print ""; print ''; } print ""; print ''; print "\n"; $i++; } print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
[".$prod->ref.']'.$fac->lignes[$i]->desc.'
 '.$fac->lignes[$i]->desc.'".price($fac->lignes[$i]->price)."'.$fac->lignes[$i]->remise_percent.' %".$fac->lignes[$i]->qty."
'; /* * Actions * */ if ($user->societe_id == 0 && $fac->paye == 0) { print '

'; if ($fac->statut == 0 && $user->rights->facture->supprimer) { print ""; } else { print ""; } print ""; print ''; print ''; print "
[Supprimer]----
"; } print "

\n"; /* * * */ } else { /* Facture non trouvée */ print "Facture inexistante ou accés refusé"; } } else { /*************************************************************************** * * * Mode Liste * * * * * ***************************************************************************/ if ($page == -1) { $page = 0 ; } if ($user->rights->facture->lire) { $limit = $conf->liste_limit; $offset = $limit * $page ; if ($sortorder == "") $sortorder="DESC"; if ($sortfield == "") $sortfield="f.datef"; $sql = "SELECT s.nom,s.idp,f.titre,f.total,f.rowid as facid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f WHERE f.fk_soc = s.idp"; if ($socidp) $sql .= " AND s.idp = $socidp"; //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; // $sql .= $db->plimit($limit + 1,$offset); $result = $db->query($sql); } if ($result) { $num = $db->num_rows(); print_barre_liste("Factures",$page,"fiche-rec.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); $i = 0; print ""; print ''; print ''; print_liste_field_titre($langs->trans("Company"),"fiche-rec.php","s.nom","","&socidp=$socidp"); print ''; print ''; print "\n"; if ($num > 0) { $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object(); $var=!$var; print ""; $class = "normal"; print '\n"; print ''; print "\n"; if (! $objp->paye) { if ($objp->fk_statut == 0) { print ''; } else { print ''; } } else { print ''; } print "\n"; $i++; } } print "
'.$langs->trans("Ref").''.$langs->trans("Amount").' 
' . $objp->titre; print "'.$objp->nom.'".price($objp->total)."brouillonimpayée 
"; $db->free(); } else { dolibarr_print_error($db); } } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>