* 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/paiement.php \ingroup compta \brief Page de création d'un paiement \version $Revision$ */ include_once("./pre.inc.php"); include_once("../paiement.class.php"); include_once(DOL_DOCUMENT_ROOT."/facture.class.php"); include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); $facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"]; $socname=isset($_GET["socname"])?$_GET["socname"]:$_POST["socname"]; $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; $page=isset($_GET["page"])?$_GET["page"]:$_POST["page"]; /* * Actions */ if ($_POST["action"] == 'add_paiement') { if ($_POST["paiementid"] > 0) { $datepaye = $db->idate(mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"])); $paiement_id = 0; $amounts = array(); foreach ($_POST as $key => $value) { if (substr($key,0,7) == 'amount_') { $other_facid = substr($key,7); $amounts[$other_facid] = $_POST[$key]; } } $db->begin(); // Creation de la ligne paiement $paiement = new Paiement($db); $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Tableau de montant $paiement->paiementid = $_POST["paiementid"]; $paiement->num_paiement = $_POST["num_paiement"]; $paiement->note = $_POST["comment"]; $paiement_id = $paiement->create($user); if ($paiement_id > 0) { // On determine le montant total du paiement $total=0; foreach ($paiement->amounts as $key => $value) { $facid = $key; $value = trim($value); $amount = round(ereg_replace(",",".",$value), 2); if (is_numeric($amount)) { $total += $amount; } } // Insertion dans llx_bank $label = "Règlement facture"; $acc = new Account($db, $_POST["accountid"]); //paiementid contient "CHQ ou VIR par exemple" $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementid, $label, $total, $paiement->num_paiement, '', $user); // Mise a jour fk_bank dans llx_paiement. On connait ainsi le paiement qui a généré l'écriture bancaire if ($bank_line_id > 0) { $paiement->update_fk_bank($bank_line_id); // Mise a jour liens (pour chaque facture concernées par le paiement) foreach ($paiement->amounts as $key => $value) { $facid = $key; $fac = new Facture($db); $fac->fetch($facid); $fac->fetch_client(); $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); } $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; $db->commit(); Header("Location: $loc"); } else { // Il y a eu erreur $db->rollback(); $fiche_erreur_message = $langs->trans("ErrorUnknown"); } } else { // Il y a eu erreur $db->rollback(); $fiche_erreur_message = $langs->trans("ErrorUnknown"); } } else { $fiche_erreur_message = '
Vous devez sélectionner un mode de paiement
'; } } /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Affichage */ llxHeader(); $html=new Form($db); if ($fiche_erreur_message) { print ''.$fiche_erreur_message.''; } if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement') { $facture = new Facture($db); $facture->fetch($facid); $sql = "SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp"; $sql .= " AND f.rowid = $facid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { $obj = $db->fetch_object($result); $total = $obj->total; print_titre($langs->trans("DoPayment")); print '
'; print ''; print ""; print "facnumber\">"; print "idp\">"; print "nom\">"; print ''; print "\n"; print "'; print ''; print '\n"; print ''; print "\n"; print "\n"; /* * Autres factures impayées */ $sql = "SELECT f.rowid as facid,f.facnumber,f.total_ttc,".$db->pdate("f.datef")." as df"; $sql .= ", sum(pf.amount) as am"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_facture = f.rowid"; $sql .= " WHERE f.fk_soc = ".$facture->socidp; $sql .= " AND f.paye = 0"; $sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée $sql .= " GROUP BY f.facnumber"; if ($db->query($sql)) { $num = $db->num_rows(); if ($num > 0) { $i = 0; print '\n"; } $db->free(); } else { dolibarr_print_error($db); } /* * */ print ''; print "
".$langs->trans("Company")." :$obj->nom
".$langs->trans("Date")." :"; $html->select_date(); print ''.$langs->trans("Comments").'
'.$langs->trans("Type").' :"; print "'; print '
Numéro :
Numéro du chèque / virement
Compte à créditer :"; print "
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=True; $total=0; $totalrecu=0; while ($i < $num) { $objp = $db->fetch_object(); $var=!$var; print ""; print '\n"; if ($objp->df > 0 ) { print "\n"; } else { print "\n"; } print '"; print '"; print '"; print '\n"; $total+=$objp->total; $total_ttc+=$objp->total_ttc; $totalrecu+=$objp->am; $i++; } if ($i > 1) { // Print total print ""; print ''; print ""; print ""; print ""; print ''; print "\n"; } print "
'.$langs->trans("Bill").''.$langs->trans("Date").''.$langs->trans("AmountTTC").''.$langs->trans("Received").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber; print ""; print strftime("%d %b %Y",$objp->df)."!!!'.price($objp->total_ttc)."'.price($objp->am)."'.price($objp->total_ttc - $objp->am)."'; $namef = "amount_".$objp->facid; print ''; print "
'.$langs->trans("TotalTTC").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
"; print "
\n"; } } } /** * \brief Affichage de la liste des paiement */ if (! $_GET["action"] && ! $_POST["action"]) { if ($page == -1) $page = 0 ; $limit = $conf->liste_limit; $offset = $limit * $page ; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="p.datep"; $sql = "SELECT ".$db->pdate("p.datep")." as dp, p.amount, f.amount as fa_amount, f.facnumber"; $sql .=", f.rowid as facid, c.libelle as paiement_type, p.num_paiement"; $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."c_paiement as c"; $sql .= " WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id"; if ($socidp) { $sql .= " AND f.fk_soc = $socidp"; } $sql .= " ORDER BY $sortfield $sortorder"; $sql .= $db->plimit( $limit +1 ,$offset); $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $var=True; print_barre_liste($langs->trans("Payments"), $page, "paiement.php","",$sortfield,$sortorder,'',$num); print ''; print ''; print_liste_field_titre($langs->trans("Bill"),"paiement.php","facnumber","","","",$sortfield); print_liste_field_titre($langs->trans("Date"),"paiement.php","dp","","","",$sortfield); print_liste_field_titre($langs->trans("Type"),"paiement.php","libelle","","","",$sortfield); print_liste_field_titre($langs->trans("Amount"),"paiement.php","fa_amount","","",'align="right"',$sortfield); print ""; print "\n"; while ($i < min($num,$limit)) { $objp = $db->fetch_object(); $var=!$var; print ""; print "\n"; print "\n"; print "\n"; print ''; print ""; $i++; } print "
 
facid\">$objp->facnumber".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount).' 
"; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>