diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php new file mode 100644 index 00000000000..58cac9fd838 --- /dev/null +++ b/htdocs/compta/facture/prelevement.php @@ -0,0 +1,253 @@ + + * Copyright (C) 2004 Éric Seigne + * 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/prelevement.php + \ingroup facture + \brief Gestion des prelevement d'une facture + \version $Revision$ +*/ + +require("./pre.inc.php"); + +$user->getrights('facture'); +if (!$user->rights->facture->lire) + accessforbidden(); + +$langs->load("bills"); + +require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); + +if ($_GET["action"] == "new") +{ + $fact = new Facture($db); + if ($fact->fetch($_GET["facid"])) + { + $result = $fact->demande_prelevement($user); + if ($result == 0) + { + Header("Location: prelevement.php?facid=".$fact->id); + } + } +} + + +/* + * Sécurité accés client + */ +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} + +llxHeader('',$langs->trans("Bill"),'Facture - Prélèvement'); + +$html = new Form($db); + +/* *************************************************************************** */ +/* */ +/* Mode fiche */ +/* */ +/* *************************************************************************** */ + +if ($_GET["facid"] > 0) +{ + $fac = New Facture($db); + if ( $fac->fetch($_GET["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(); + + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("CardBill"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Apercu"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Prelevement"); + $hselected = $h; + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Note"); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans("Info"); + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); + + /* + * Facture + */ + print ''; + print ''; + print ''; + + print ""; + + print ''; + print "\n"; + print ""; + + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print "
'.$langs->trans("Company").''; + print ''.$soc->nom.'Conditions de réglement : " . $fac->cond_reglement ."
'.$langs->trans("Date").'".strftime("%A %d %B %Y",$fac->date)."Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) ."
'.$langs->trans("Author").''.$author->fullname.'
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$conf->monnaie.' HT 
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$conf->monnaie.' HT 
"; + + print "
\n"; + + // Valider + if ($fac->statut > 0 && $fac->paye == 0) + { + if ($user->rights->facture->creer) + { + print 'Faire une demande de prélèvement'; + } + } + print "

"; + /* + * Prélèvement + */ + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var=True; + + $sql = "SELECT pfd.rowid, pfd.traite,".$db->pdate("pfd.date_demande")." as date_demande"; + $sql .= " ,".$db->pdate("pfd.date_traite")." as date_traite"; + $sql .= " , pfd.fk_prelevement"; + $sql .= " , u.name, u.firstname"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE fk_facture = ".$fac->id; + $sql .= " AND pfd.fk_user_demande = u.rowid"; + $sql .= " AND pfd.traite = 0"; + $sql .= " ORDER BY pfd.date_demande DESC"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($i); + $var=!$var; + + print ""; + print '\n"; + print ''; + print ''; + print ''; + print "\n"; + $i++; + } + + $db->free(); + } + else + { + print $db->error() . ' ' . $sql; + } + + $sql = "SELECT pfd.rowid, pfd.traite,".$db->pdate("pfd.date_demande")." as date_demande"; + $sql .= " ,".$db->pdate("pfd.date_traite")." as date_traite"; + $sql .= " , pfd.fk_prelevement"; + $sql .= " , u.name, u.firstname"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; + $sql .= " , ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE fk_facture = ".$fac->id; + $sql .= " AND pfd.fk_user_demande = u.rowid"; + $sql .= " AND pfd.traite = 1"; + $sql .= " ORDER BY pfd.date_demande DESC"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($i); + $var=!$var; + + print ""; + + print '\n"; + + print '\n"; + print '\n"; + + print ''; + + print "\n"; + $i++; + } + + $db->free(); + } + else + { + print $db->error() . ' ' . $sql; + } + + print "
Date demandeDate traitementBon prélèvementUtilisateur
'.strftime("%d/%m/%Y",$obj->date_demande)."--'.$obj->firstname." ".$obj->name.'
'.strftime("%d/%m/%Y",$obj->date_demande)."'.strftime("%d/%m/%Y",$obj->date_traite)."'; + print ''.$obj->fk_prelevement."'.$obj->firstname." ".$obj->name.'
"; + + } + else + { + /* Facture non trouvée */ + print $langs->trans("ErrorBillNotFound"); + } +} + +print ''; + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?>