diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index 0a78f5d9297..1f30e15e70f 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -18,14 +18,13 @@
*
* $Id$
* $Source$
- *
*/
/**
- \file htdocs/compta/paiement.php
- \ingroup compta
- \brief Page de création d'un paiement
- \version $Revision$
+ \file htdocs/compta/paiement.php
+ \ingroup compta
+ \brief Page de création d'un paiement
+ \version $Revision$
*/
include_once("./pre.inc.php");
@@ -33,6 +32,9 @@ require_once(DOL_DOCUMENT_ROOT."/paiement.class.php");
include_once(DOL_DOCUMENT_ROOT."/facture.class.php");
include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php");
+$langs->load("bills");
+$langs->load("banks");
+
$facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"];
$socname=isset($_GET["socname"])?$_GET["socname"]:$_POST["socname"];
@@ -46,146 +48,153 @@ $page=isset($_GET["page"])?$_GET["page"]:$_POST["page"];
*/
if ($_POST["action"] == 'add_paiement')
{
- $error = 0;
+ $error = 0;
- if ($_POST["paiementid"] > 0)
+ if ($_POST["paiementid"] > 0)
{
- $datepaye = $db->idate(mktime(12, 0 , 0,
- $_POST["remonth"],
- $_POST["reday"],
- $_POST["reyear"]));
-
- $paiement_id = 0;
- $total = 0;
- $amounts = array();
- foreach ($_POST as $key => $value)
+ $datepaye = $db->idate(mktime(12, 0 , 0,
+ $_POST["remonth"],
+ $_POST["reday"],
+ $_POST["reyear"]));
+
+ $paiement_id = 0;
+ $total = 0;
+ $amounts = array();
+ foreach ($_POST as $key => $value)
{
- if (substr($key,0,7) == 'amount_')
+ if (substr($key,0,7) == 'amount_')
{
- $other_facid = substr($key,7);
-
- $amounts[$other_facid] = $_POST[$key];
- $total = $total + $amounts[$other_facid];
+ $other_facid = substr($key,7);
+
+ $amounts[$other_facid] = $_POST[$key];
+ $total = $total + $amounts[$other_facid];
}
}
-
- if ($total > 0)
- {
- $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 ($total > 0)
+ {
- 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;
- }
- }
-
- if ($conf->banque->enabled && $_POST["accountid"])
- {
- // 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);
-
+ $db->begin();
- // 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)",
- 'payment');
- $acc->add_url_line($bank_line_id,
- $fac->client->id,
- DOL_URL_ROOT.'/compta/fiche.php?socid=',
- $fac->client->nom,
- 'company');
- }
-
- }
- else
- {
- $error++;
- }
- }
-
- }
- else
- {
- $error++;
- }
+ // 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"];
-
- if ($error == 0)
- {
- $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
- {
- $fiche_erreur_message = '
Aucun montants indiqués
';
- }
+ $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;
+ }
+ }
+
+ if ($conf->banque->enabled)
+ {
+ // Si module bank actif, un compte est obligatoire lors de la saisie
+ // d'un paiement
+ if (! $_POST["accountid"])
+ {
+ $fiche_erreur_message = ''.$langs->trans("ErrorFieldRequired",$langs->trans("AccountToCredit")).'
';
+ $error++;
+ }
+ else
+ {
+ // 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)",
+ 'payment');
+ $acc->add_url_line($bank_line_id,
+ $fac->client->id,
+ DOL_URL_ROOT.'/compta/fiche.php?socid=',
+ $fac->client->nom,
+ 'company');
+ }
+
+ }
+ else
+ {
+ $error++;
+ }
+ }
+ }
+
+ }
+ else
+ {
+ $error++;
+ }
+
+
+ if ($error == 0)
+ {
+ $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
+ $db->commit();
+ Header("Location: $loc");
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ else
+ {
+ $fiche_erreur_message = ''.$langs->trans("ErrorFieldRequired",$langs->trans("Amount")).'
';
+ }
}
- else
+ else
{
- $fiche_erreur_message = 'Vous devez sélectionner un mode de paiement
';
+ $fiche_erreur_message = ''.$langs->trans("ErrorFieldRequired",$langs->trans("PaymentMode")).'
';
}
}
-/*
- * Sécurité accés client
- */
+// Sécurité accés client
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
+
/*
* Affichage
*/
@@ -196,204 +205,164 @@ $html=new Form($db);
if ($fiche_erreur_message)
{
- print '| '.$fiche_erreur_message.' |
';
+ print '| '.$fiche_erreur_message.' |
';
}
-
-if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
+if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
{
- $facture = new Facture($db);
- $facture->fetch($facid);
+ $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";
+ $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";
- $resql = $db->query($sql);
- if ($resql)
+ $resql = $db->query($sql);
+ if ($resql)
{
- $num = $db->num_rows($resql);
- if ($num)
- {
- $obj = $db->fetch_object($resql);
+ $num = $db->num_rows($resql);
+ if ($num)
+ {
+ $obj = $db->fetch_object($resql);
- $total = $obj->total;
+ $total = $obj->total;
- print_titre($langs->trans("DoPayment"));
+ print_titre($langs->trans("DoPayment"));
- print '\n";
+ }
}
}
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 32bb494314b..2b90b5c97a3 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -636,26 +636,32 @@ class Form
}
- /**
- * \brief Retourne la liste des comptes
- * \param selected Id compte présélectionné
- * \param htmlname Nom de la zone select
- * \param statut Statut des comptes recherchés
- * \param filtre Pour filtre sur la liste
- */
- function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='')
+ /**
+ * \brief Retourne la liste des comptes
+ * \param selected Id compte présélectionné
+ * \param htmlname Nom de la zone select
+ * \param statut Statut des comptes recherchés
+ * \param filtre Pour filtre sur la liste
+ * \param useempty Affiche valeur vide dans liste
+ */
+ function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='',$useempty=0)
{
global $langs;
$sql = "SELECT rowid, label, bank";
$sql.= " FROM ".MAIN_DB_PREFIX."bank_account";
- $sql.= " WHERE clos = '".$satut."'";
+ $sql.= " WHERE clos = '".$statut."'";
if ($filtre) $sql.=" AND ".$filtre;
$sql.= " ORDER BY rowid";
$result = $this->db->query($sql);
if ($result)
{
print '