* Copyright (C) 2004 Éric Seigne * Copyright (C) 2004-2005 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"); require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); $user->getrights('facture'); if (!$user->rights->facture->lire) accessforbidden(); $langs->load("bills"); $langs->load("banks"); $langs->load("withdrawals"); // Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Actions */ 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); exit; } else { $mesg='
'.$fact->error.'
'; } } } if ($_GET["action"] == "delete") { $fact = new Facture($db); if ($fact->fetch($_GET["facid"])) { $result = $fact->demande_prelevement_delete($user,$_GET["did"]); if ($result == 0) { Header("Location: prelevement.php?facid=".$fact->id); } } } llxHeader('',$langs->trans("Bill")); $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode fiche */ /* */ /* *************************************************************************** */ if ($_GET["facid"] > 0) { $fac = New Facture($db); if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) { if ($mesg) print $mesg.'
'; $soc = new Societe($db, $fac->socidp); $soc->fetch($fac->socidp); $author = new User($db); if ($fac->user_author) { $author->id = $fac->user_author; $author->fetch(); } $head = facture_prepare_head($fac); $hselected = 2; if ($conf->use_preview_tabs) $hselected++; dolibarr_fiche_head($head, $hselected, $langs->trans('Bill').' : '.$fac->ref); /* * Facture */ print ''; // Reference du facture print '"; // Societe print ''; print ''; print ''; // Dates print ''; print ''; print '"; // Conditions et modes de réglement print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").''; print $fac->ref; print "
'.$langs->trans("Company").''; print ''.$soc->nom.'
'.$langs->trans("Date").''.dolibarr_print_date($fac->date,"%A %d %B %Y").''.$langs->trans("DateClosing").'' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y"); if ($fac->date_lim_reglement < (time() - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans("Late")); print "
'.$langs->trans("PaymentConditions").''; $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none"); print ''.$langs->trans("PaymentMode").''; $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); print '
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->monnaie).' 
RIB'; print $soc->display_rib(); print '
'; print ''; /* * Demande de prélèvement * */ $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.amount"; $sql .= " , u.rowid as user_id, u.name, u.firstname, u.code"; $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_sql = $db->query($sql); if ($result_sql) { $num = $db->num_rows($result_sql); } print "
\n"; // Valider if ($fac->statut > 0 && $fac->paye == 0 && $fac->mode_reglement_code == 'PRE' && $num == 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 ''; print ''; $var=True; if ($result_sql) { $i = 0; while ($i < $num) { $obj = $db->fetch_object($result_sql); $var=!$var; print ""; print '\n"; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $i++; } $db->free($result_sql); } else { dolibarr_print_error($db); } $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_bons, pfd.amount"; $sql .= " , u.rowid as user_id, u.name, u.firstname, u.code"; $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($result); $i = 0; while ($i < $num) { $obj = $db->fetch_object($result); $var=!$var; print ""; print '\n"; print '\n"; print ''; print '\n"; print ''; print ''; print ''; print "\n"; $i++; } $db->free($result); } else { dolibarr_print_error($db); } print "
'.$langs->trans("DateRequest").''.$langs->trans("DateProcess").''.$langs->trans("Amount").''.$langs->trans("WithdrawalReceipt").''.$langs->trans("User").'  
'.dolibarr_print_date($obj->date_demande)."En attente de traitement'.price($obj->amount).'-'.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.' '; print ''; print img_delete(); print '
'.dolibarr_print_date($obj->date_demande)."'.dolibarr_print_date($obj->date_traite)."'.price($obj->amount).''; print ''.$obj->fk_prelevement_bons."'.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'  
"; } else { /* Facture non trouvée */ print $langs->trans("ErrorBillNotFound",$_GET["facid"]); } } print ''; $db->close(); llxFooter('$Date$ - $Revision$'); ?>