Correction bug 13668

This commit is contained in:
Rodolphe Quiedeville 2005-07-21 12:38:35 +00:00
parent fcfe9d55fb
commit 72a890b258

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -46,6 +46,8 @@ $page=isset($_GET["page"])?$_GET["page"]:$_POST["page"];
*/ */
if ($_POST["action"] == 'add_paiement') if ($_POST["action"] == 'add_paiement')
{ {
$error = 0;
if ($_POST["paiementid"] > 0) if ($_POST["paiementid"] > 0)
{ {
$datepaye = $db->idate(mktime(12, 0 , 0, $datepaye = $db->idate(mktime(12, 0 , 0,
@ -76,6 +78,7 @@ if ($_POST["action"] == 'add_paiement')
$paiement->note = $_POST["comment"]; $paiement->note = $_POST["comment"];
$paiement_id = $paiement->create($user); $paiement_id = $paiement->create($user);
if ($paiement_id > 0) if ($paiement_id > 0)
{ {
// On determine le montant total du paiement // On determine le montant total du paiement
@ -91,13 +94,23 @@ if ($_POST["action"] == 'add_paiement')
} }
} }
if ($conf->banque->enabled && $_POST["accountid"])
{
// Insertion dans llx_bank // Insertion dans llx_bank
$label = "Règlement facture"; $label = "Règlement facture";
$acc = new Account($db, $_POST["accountid"]); $acc = new Account($db, $_POST["accountid"]);
//paiementid contient "CHQ ou VIR par exemple" //paiementid contient "CHQ ou VIR par exemple"
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementid, $label, $total, $paiement->num_paiement, '', $user); $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
// 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) if ($bank_line_id > 0)
{ {
$paiement->update_fk_bank($bank_line_id); $paiement->update_fk_bank($bank_line_id);
@ -109,15 +122,39 @@ if ($_POST["action"] == 'add_paiement')
$fac = new Facture($db); $fac = new Facture($db);
$fac->fetch($facid); $fac->fetch($facid);
$fac->fetch_client(); $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,
$acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); $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);
} }
}
else
{
$error++;
}
}
}
else
{
$error++;
}
if ($error == 0)
{
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
$db->commit(); $db->commit();
Header("Location: $loc"); Header("Location: $loc");
} }
else else
{ {
@ -125,13 +162,7 @@ if ($_POST["action"] == 'add_paiement')
$db->rollback(); $db->rollback();
$fiche_erreur_message = $langs->trans("ErrorUnknown"); $fiche_erreur_message = $langs->trans("ErrorUnknown");
} }
}
else
{
// Il y a eu erreur
$db->rollback();
$fiche_erreur_message = $langs->trans("ErrorUnknown");
}
} }
else else
{ {
@ -171,13 +202,13 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp"; $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 .= " AND f.rowid = $facid";
$result = $db->query($sql); $resql = $db->query($sql);
if ($result) if ($resql)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($resql);
if ($num) if ($num)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($resql);
$total = $obj->total; $total = $obj->total;
@ -203,14 +234,14 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY id"; $sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY id";
$result = $db->query($sql); $resql = $db->query($sql);
if ($result) if ($resql)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($resql);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$objopt = $db->fetch_object($result); $objopt = $db->fetch_object($resql);
print "<option value=\"$objopt->id\">$objopt->libelle</option>\n"; print "<option value=\"$objopt->id\">$objopt->libelle</option>\n";
$i++; $i++;
} }
@ -219,22 +250,26 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
print "</td>\n"; print "</td>\n";
print '<td rowspan="3" valign="top">'; print '<td rowspan="3" valign="top">';
print '<textarea name="comment" wrap="soft" cols="40" rows="6"></textarea></td></tr>'; print '<textarea name="comment" wrap="soft" cols="40" rows="4"></textarea></td></tr>';
print "<tr><td>Numéro :</td><td><input name=\"num_paiement\" type=\"text\"><br><em>Numéro du chèque / virement</em></td></tr>\n"; print "<tr><td>Numéro :</td><td><input name=\"num_paiement\" type=\"text\"><br><em>Numéro du chèque / virement</em></td></tr>\n";
if ($conf->banque->enabled)
{
print "<tr><td>Compte à créditer :</td><td><select name=\"accountid\">\n"; print "<tr><td>Compte à créditer :</td><td><select name=\"accountid\">\n";
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account ORDER BY rowid"; $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account ORDER BY rowid";
$result = $db->query($sql); $resql = $db->query($sql);
if ($result) if ($resql)
{ {
$num = $db->num_rows(); $num = $db->num_rows();
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$objopt = $db->fetch_object($result); $objopt = $db->fetch_object($resql);
print '<option value="'.$objopt->rowid.'"'; print '<option value="'.$objopt->rowid.'"';
if (defined("FACTURE_RIB_NUMBER") && FACTURE_RIB_NUMBER == $objopt->rowid) if (defined("FACTURE_RIB_NUMBER") && FACTURE_RIB_NUMBER == $objopt->rowid)
{ {
@ -243,10 +278,17 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
print '>'.$objopt->label.'</option>'; print '>'.$objopt->label.'</option>';
$i++; $i++;
} }
$db->free($resql);
} }
print "</select>"; print "</select>";
print "</td></tr>\n"; print "</td></tr>\n";
}
else
{
print '<tr><td colspan="2">&nbsp;</td></tr>';
}
/* /*
* Autres factures impayées * Autres factures impayées
*/ */
@ -260,9 +302,11 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
$sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée $sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée
$sql .= " GROUP BY f.facnumber"; $sql .= " GROUP BY f.facnumber";
if ($db->query($sql)) $resql = $db->query($sql);
if ($resql)
{ {
$num = $db->num_rows(); $num = $db->num_rows($resql);
if ($num > 0) if ($num > 0)
{ {
@ -283,7 +327,7 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object(); $objp = $db->fetch_object($resql);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
@ -329,7 +373,7 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'add_paiement')
} }
print "</table></td></tr>\n"; print "</table></td></tr>\n";
} }
$db->free(); $db->free($resql);
} }
else else
{ {
@ -372,11 +416,11 @@ if (! $_GET["action"] && ! $_POST["action"])
$sql .= " ORDER BY $sortfield $sortorder"; $sql .= " ORDER BY $sortfield $sortorder";
$sql .= $db->plimit( $limit +1 ,$offset); $sql .= $db->plimit( $limit +1 ,$offset);
$result = $db->query($sql); $resql = $db->query($sql);
if ($result) if ($resql)
{ {
$num = $db->num_rows(); $num = $db->num_rows($resql);
$i = 0; $i = 0;
$var=True; $var=True;
@ -393,7 +437,7 @@ if (! $_GET["action"] && ! $_POST["action"])
while ($i < min($num,$limit)) while ($i < min($num,$limit))
{ {
$objp = $db->fetch_object(); $objp = $db->fetch_object($resql);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print "<td><a href=\"facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n"; print "<td><a href=\"facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n";