Fix: bad error management

This commit is contained in:
Regis Houssin 2010-09-30 20:06:38 +00:00
parent 6838247724
commit cb5fde8c62

View File

@ -24,8 +24,8 @@
*/ */
require('../main.inc.php'); require('../main.inc.php');
include_once(DOL_DOCUMENT_ROOT."/compta/chargesociales.class.php"); include_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
$langs->load("bills"); $langs->load("bills");
@ -44,10 +44,12 @@ if ($user->societe_id > 0)
*/ */
if ($_POST["action"] == 'add_paiement') if ($_POST["action"] == 'add_paiement')
{ {
$error=0;
if ($_POST["cancel"]) if ($_POST["cancel"])
{ {
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
Header("Location: $loc"); Header("Location: ".$loc);
exit; exit;
} }
@ -63,12 +65,18 @@ if ($_POST["action"] == 'add_paiement')
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")); $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date"));
$error++; $error++;
} }
if ($conf->banque->enabled && ! $_POST["accountid"] > 0)
{
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit"));
$error++;
}
if (! $error) if (! $error)
{ {
$paiement_id = 0; $paymentid = 0;
// Read possible payments // Read possible payments
// FIXME add error message if no payment is defined
$amounts = array(); $amounts = array();
foreach ($_POST as $key => $value) foreach ($_POST as $key => $value)
{ {
@ -90,9 +98,9 @@ if ($_POST["action"] == 'add_paiement')
$paiement->paiementtype = $_POST["paiementtype"]; $paiement->paiementtype = $_POST["paiementtype"];
$paiement->num_paiement = $_POST["num_paiement"]; $paiement->num_paiement = $_POST["num_paiement"];
$paiement->note = $_POST["note"]; $paiement->note = $_POST["note"];
$paiement_id = $paiement->create($user); $paymentid = $paiement->create($user);
if ($paiement_id > 0) if ($paymentid > 0)
{ {
// On determine le montant total du paiement // On determine le montant total du paiement
$total=0; $total=0;
@ -108,7 +116,7 @@ if ($_POST["action"] == 'add_paiement')
$langs->load("banks"); $langs->load("banks");
$label = $langs->transnoentities("SocialContributionPayment"); $label = $langs->transnoentities("SocialContributionPayment");
$acc = new Account($db, $_POST["accountid"]); $acc = new Account($db, $_POST["accountid"]);
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user); $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -$total, $paiement->num_paiement, '', $user);
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire // Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0) if ($bank_line_id > 0)
@ -125,7 +133,7 @@ if ($_POST["action"] == 'add_paiement')
$db->commit(); $db->commit();
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
Header("Location: $loc"); Header("Location: ".$loc);
exit; exit;
} }
else { else {
@ -136,7 +144,7 @@ if ($_POST["action"] == 'add_paiement')
else else
{ {
$db->rollback(); $db->rollback();
$mesg = "Failed to create payment: paiement_id=$paiement_id ".$db->error(); $mesg = "Failed to create payment: paiement_id=".$paymentid." ".$db->error();
} }
} }
@ -208,13 +216,14 @@ if ($_GET["action"] == 'create')
print "<input type=\"hidden\" name=\"chid\" value=\"$chid\">"; print "<input type=\"hidden\" name=\"chid\" value=\"$chid\">";
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
$datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; $datepaye = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0;
$html->select_date($datepayment,'','','','',"add_paiement",1,1); $html->select_date($datepayment,'','','','',"add_paiement",1,1);
print "</td>"; print "</td>";
print '<td>'.$langs->trans("Comments").'</td></tr>'; print '<td>'.$langs->trans("Comments").'</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
$html->select_types_paiements($charge->paiementtype, "paiementtype"); $html->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype");
print "</td>\n"; print "</td>\n";
print '<td rowspan="3" valign="top"><textarea name="comment" wrap="soft" cols="40" rows="'.ROWS_3.'"></textarea></td></tr>'; print '<td rowspan="3" valign="top"><textarea name="comment" wrap="soft" cols="40" rows="'.ROWS_3.'"></textarea></td></tr>';
@ -222,7 +231,7 @@ if ($_GET["action"] == 'create')
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToCredit').'</td>'; print '<td class="fieldrequired">'.$langs->trans('AccountToCredit').'</td>';
print '<td>'; print '<td>';
$html->select_comptes($charge->accountid, "accountid", 0, "courant=1"); // Affiche liste des comptes courant $html->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, "courant=1",1); // Affiche liste des comptes courant
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans('Numero'); print '<tr><td>'.$langs->trans('Numero');
@ -235,7 +244,8 @@ if ($_GET["action"] == 'create')
$num = 1; $num = 1;
$i = 0; $i = 0;
print '<tr><td colspan="3">'; print '<tr><td colspan="3">';
print '<table class="noborder" width="100%">';
print '<table class="nobordernopadding" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
//print '<td>'.$langs->trans("SocialContribution").'</td>'; //print '<td>'.$langs->trans("SocialContribution").'</td>';
print '<td align="left">'.$langs->trans("DateDue").'</td>'; print '<td align="left">'.$langs->trans("DateDue").'</td>';