New: Possibilité de modifier les conditions de réglements et le mode de paiement sur une facture brouillon.

This commit is contained in:
Laurent Destailleur 2005-09-03 12:47:56 +00:00
parent 5aa5f38426
commit bffcbc1673
7 changed files with 754 additions and 546 deletions

View File

@ -73,6 +73,29 @@ if ($_POST["action"] == 'classin')
$facture->classin($_POST["projetid"]); $facture->classin($_POST["projetid"]);
} }
if ($_POST["action"] == 'setmode')
{
$facture = new Facture($db);
$facture->fetch($_GET["facid"]);
$result=$facture->mode_reglement($_POST["mode_reglement_id"]);
if ($result < 0) dolibarr_print_error($db,$facture->error);
}
if ($_POST["action"] == 'setconditions')
{
$facture = new Facture($db);
$facture->fetch($_GET["facid"]);
$result=$facture->cond_reglement($_POST["cond_reglement_id"]);
if ($result < 0) dolibarr_print_error($db,$facture->error);
}
if ($_POST["action"] == 'classin')
{
$facture = new Facture($db);
$facture->fetch($_GET["facid"]);
$facture->classin($_POST["projetid"]);
}
/* /*
* Insertion facture * Insertion facture
*/ */
@ -95,8 +118,8 @@ if ($_POST["action"] == 'add')
else else
{ {
$facture->projetid = $_POST["projetid"]; $facture->projetid = $_POST["projetid"];
$facture->cond_reglement = $_POST["condid"]; $facture->cond_reglement_id = $_POST["cond_reglement_id"];
$facture->mode_reglement = $_POST["mode_reglement"]; $facture->mode_reglement_id = $_POST["mode_reglement_id"];
$facture->amount = $_POST["amount"]; $facture->amount = $_POST["amount"];
$facture->remise = $_POST["remise"]; $facture->remise = $_POST["remise"];
$facture->remise_percent = $_POST["remise_percent"]; $facture->remise_percent = $_POST["remise_percent"];
@ -555,12 +578,12 @@ if ($_GET["action"] == 'create')
// Conditions de réglement // Conditions de réglement
$id_condition_paiements_defaut=1; $id_condition_paiements_defaut=1;
print "<tr><td nowrap>".$langs->trans("PaymentConditions")."</td><td>"; print "<tr><td nowrap>".$langs->trans("PaymentConditions")."</td><td>";
$html->select_conditions_paiements($id_condition_paiements_defaut,'condid'); $html->select_conditions_paiements($id_condition_paiements_defaut,'cond_reglement_id');
print "</td></tr>"; print "</td></tr>";
// Mode de réglement // Mode de réglement
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>"; print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
$html->select_types_paiements('','mode_reglement'); $html->select_types_paiements('','mode_reglement_id');
print "</td></tr>"; print "</td></tr>";
// Projet // Projet
@ -864,7 +887,7 @@ else
$head[$h][1] = $langs->trans("Preview"); $head[$h][1] = $langs->trans("Preview");
$h++; $h++;
if ($fac->mode_reglement == 3) if ($fac->mode_reglement_code == 'PRE')
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("StandingOrders"); $head[$h][1] = $langs->trans("StandingOrders");
@ -927,16 +950,45 @@ else
print '</td></tr>'; print '</td></tr>';
// Conditions et modes de réglement // Conditions et modes de réglement
print '<tr><td>'.$langs->trans("PaymentConditions").'</td><td colspan="3">'. $fac->cond_reglement . '</td>'; print '<tr><td>';
print '<td width="25%">'.$langs->trans("PaymentMode").'</td><td width="25%">'. $fac->mode_reglement . '</td></tr>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans("PaymentConditions");
print '</td>';
if ($_GET["action"] != "editconditions" && $fac->brouillon) print '<td align="right"><a href="facture.php?action=editconditions&amp;facid='.$fac->id.'">'.img_edit($langs->trans("SetConditions")).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($_GET["action"] == "editconditions")
{
$html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"cond_reglement_id");
}
else
{
$html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none");
}
print '</td>';
print '<td width="25%">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans("PaymentMode");
print '</td>';
if ($_GET["action"] != "editmode" && $fac->brouillon) print '<td align="right"><a href="facture.php?action=editmode&amp;facid='.$fac->id.'">'.img_edit($langs->trans("SetMode")).'</a></td>';
print '</tr></table>';
print '</td><td width="25%">';
if ($_GET["action"] == "editmode")
{
$html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"mode_reglement_id");
}
else
{
$html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none");
}
print '</td></tr>';
print '<tr>'; print '<tr>';
// Projet // Projet
if ($conf->projet->enabled) if ($conf->projet->enabled)
{ {
$langs->load("projects"); $langs->load("projects");
print '<td height="10">'; print '<td>';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans("Project"); print $langs->trans("Project");
print '</td>'; print '</td>';
@ -952,8 +1004,10 @@ else
$html->form_project($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->fk_soc,$fac->projetid,"none"); $html->form_project($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->fk_soc,$fac->projetid,"none");
} }
print "</td>"; print "</td>";
} else { }
print '<td height="10">&nbsp;</td><td colspan="3">&nbsp;</td>'; else
{
print '<td>&nbsp;</td><td colspan="3">&nbsp;</td>';
} }
print '<td rowspan="8" colspan="2" valign="top">'; print '<td rowspan="8" colspan="2" valign="top">';
@ -1011,9 +1065,9 @@ else
print "</td></tr>"; print "</td></tr>";
print "<tr><td height=\"10\">".$langs->trans("Author")."</td><td colspan=\"3\">$author->fullname</td></tr>"; print "<tr><td>".$langs->trans("Author")."</td><td colspan=\"3\">$author->fullname</td></tr>";
print '<tr><td height=\"10\">'.$langs->trans("GlobalDiscount").'</td>'; print '<tr><td>'.$langs->trans("GlobalDiscount").'</td>';
if ($fac->brouillon == 1 && $user->rights->facture->creer) if ($fac->brouillon == 1 && $user->rights->facture->creer)
{ {
print '<form action="facture.php?facid='.$fac->id.'" method="post">'; print '<form action="facture.php?facid='.$fac->id.'" method="post">';
@ -1027,17 +1081,17 @@ else
} }
print '</tr>'; print '</tr>';
print '<tr><td height=\"10\">'.$langs->trans("AmountHT").'</td>'; print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>'; print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print '<tr><td height=\"10\">'.$langs->trans("VAT").'</td><td align="right" colspan="2">'.price($fac->total_tva).'</td>'; print '<tr><td>'.$langs->trans("VAT").'</td><td align="right" colspan="2">'.price($fac->total_tva).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print '<tr><td height=\"10\">'.$langs->trans("AmountTTC").'</td><td align="right" colspan="2">'.price($fac->total_ttc).'</td>'; print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right" colspan="2">'.price($fac->total_ttc).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
// Statut // Statut
print '<tr><td height=\"10\">'.$langs->trans("Status").'</td><td align="left" colspan="3">'.($fac->getLibStatut()).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td align="left" colspan="3">'.($fac->getLibStatut()).'</td></tr>';
if ($fac->note) if ($fac->note)
{ {

View File

@ -86,7 +86,7 @@ if ($_GET["facid"] > 0)
$hselected = $h; $hselected = $h;
$h++; $h++;
if ($fac->mode_reglement == 3) if ($fac->mode_reglement_code == 'PRE')
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("StandingOrders"); $head[$h][1] = $langs->trans("StandingOrders");
@ -107,6 +107,8 @@ if ($_GET["facid"] > 0)
* Facture * Facture
*/ */
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Societe
print '<tr><td>'.$langs->trans("Company").'</td>'; print '<tr><td>'.$langs->trans("Company").'</td>';
print '<td colspan="5">'; print '<td colspan="5">';
print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>'; print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>';
@ -120,14 +122,18 @@ if ($_GET["facid"] > 0)
print "</td></tr>"; print "</td></tr>";
// Conditions et modes de réglement // Conditions et modes de réglement
print '<tr><td>'.$langs->trans("PaymentConditions").'</td><td colspan="3">'. $fac->cond_reglement . '</td>'; print '<tr><td>'.$langs->trans("PaymentConditions").'</td><td colspan="3">';
print '<td width="25%">'.$langs->trans("PaymentMode").'</td><td width="25%">'. $fac->mode_reglement . '</td></tr>'; $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none");
print '</td>';
print '<td width="25%">'.$langs->trans("PaymentMode").'</td><td width="25%">';
$html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none");
print '</td></tr>';
print '<tr>'; print '<tr>';
if ($conf->projet->enabled) if ($conf->projet->enabled)
{ {
$langs->load("projects"); $langs->load("projects");
print '<td height=\"10\">'.$langs->trans("Project").'</td><td colspan="3">'; print '<td>'.$langs->trans("Project").'</td><td colspan="3">';
if ($fac->projetid > 0) if ($fac->projetid > 0)
{ {
$projet = New Project($db); $projet = New Project($db);
@ -142,7 +148,7 @@ if ($_GET["facid"] > 0)
} }
else else
{ {
print '<td height=\"10\">&nbsp;</td><td colspan="3">'; print '<td>&nbsp;</td><td colspan="3">';
print "&nbsp;</td>"; print "&nbsp;</td>";
} }
print '<td colspan="2" rowspan="4" valign="top" width="50%">'; print '<td colspan="2" rowspan="4" valign="top" width="50%">';
@ -229,13 +235,13 @@ if ($_GET["facid"] > 0)
print "</td></tr>"; print "</td></tr>";
print "<tr><td height=\"10\">".$langs->trans("Author")."</td><td colspan=\"3\">$author->fullname</td>"; print "<tr><td>".$langs->trans("Author")."</td><td colspan=\"3\">$author->fullname</td>";
print '<tr><td height=\"10\" nowrap>'.$langs->trans("GlobalDiscount").'</td>'; print '<tr><td nowrap>'.$langs->trans("GlobalDiscount").'</td>';
print '<td align="right" colspan="2">'.$fac->remise_percent.'</td>'; print '<td align="right" colspan="2">'.$fac->remise_percent.'</td>';
print '<td>%</td></tr>'; print '<td>%</td></tr>';
print '<tr><td height=\"10\">'.$langs->trans("AmountHT").'</td>'; print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>'; print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 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
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,7 +18,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -40,33 +39,43 @@ llxHeader();
* *
*/ */
$facture = new Facture($db); $fac = new Facture($db);
$facture->fetch($_GET["facid"]); $fac->fetch($_GET["facid"]);
$facture->info($_GET["facid"]); $fac->info($_GET["facid"]);
$soc = new Societe($db, $facture->socidp); $soc = new Societe($db, $fac->socidp);
$soc->fetch($facture->socidp); $soc->fetch($fac->socidp);
$h = 0; $h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$facture->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("CardBill"); $head[$h][1] = $langs->trans("CardBill");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$facture->id;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Preview"); $head[$h][1] = $langs->trans("Preview");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$facture->id;
if ($fac->mode_reglement_code == 'PRE')
{
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("StandingOrders");
$h++;
}
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Note"); $head[$h][1] = $langs->trans("Note");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$facture->id;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Info"); $head[$h][1] = $langs->trans("Info");
$hselected = $h; $hselected = $h;
$h++; $h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $facture->ref"); dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref");
print '<table width="100%"><tr><td>'; print '<table width="100%"><tr><td>';
dolibarr_print_object_info($facture); dolibarr_print_object_info($fac);
print '</td></tr></table>'; print '</td></tr></table>';
print '</div>'; print '</div>';

View File

@ -47,8 +47,8 @@ if ($user->societe_id > 0)
} }
$facture = new Facture($db); $fac = new Facture($db);
$facture->fetch($_GET["facid"]); $fac->fetch($_GET["facid"]);
/******************************************************************************/ /******************************************************************************/
@ -57,7 +57,7 @@ $facture->fetch($_GET["facid"]);
if ($_POST["action"] == 'update' && $user->rights->facture->creer) if ($_POST["action"] == 'update' && $user->rights->facture->creer)
{ {
$facture->update_note($_POST["note"]); $fac->update_note($_POST["note"]);
} }
@ -68,37 +68,38 @@ if ($_POST["action"] == 'update' && $user->rights->facture->creer)
llxHeader(); llxHeader();
$html = new Form($db);
if ($_GET["facid"]) if ($_GET["facid"])
{ {
$soc = new Societe($db, $facture->socidp); $soc = new Societe($db, $fac->socidp);
$soc->fetch($facture->socidp); $soc->fetch($fac->socidp);
$h=0; $h=0;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$facture->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("CardBill"); $head[$h][1] = $langs->trans("CardBill");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$facture->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Preview"); $head[$h][1] = $langs->trans("Preview");
$h++; $h++;
if ($facture->mode_reglement == 3) if ($fac->mode_reglement_code == 'PRE')
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$facture->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("StandingOrders"); $head[$h][1] = $langs->trans("StandingOrders");
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$facture->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Note"); $head[$h][1] = $langs->trans("Note");
$hselected = $h; $hselected = $h;
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$facture->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Info"); $head[$h][1] = $langs->trans("Info");
$h++; $h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $facture->ref"); dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref");
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -107,23 +108,30 @@ if ($_GET["facid"])
print '<td colspan="3">'; print '<td colspan="3">';
print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>'; print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>';
// Dates
print '<tr><td>'.$langs->trans("Date").'</td>'; print '<tr><td>'.$langs->trans("Date").'</td>';
print '<td>'.dolibarr_print_date($facture->date,"%A %d %B %Y")."</td>\n"; print '<td>'.dolibarr_print_date($fac->date,"%A %d %B %Y").'</td>';
print '<td width="25%">'.$langs->trans("DateClosing").'</td><td width="25%">'.dolibarr_print_date($facture->date_lim_reglement,"%A %d %B %Y") ."</td></tr>"; print '<td>'.$langs->trans("DateClosing").'</td><td>' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y");
if ($fac->paye == 0 && $fac->date_lim_reglement < (time() - $warning_delay)) print img_warning($langs->trans("Late"));
print "</td></tr>";
// Conditions et modes de réglement // Conditions et modes de réglement
print '<tr><td>'.$langs->trans("PaymentConditions").'</td><td>'. $facture->cond_reglement . '</td>'; print '<tr><td>'.$langs->trans("PaymentConditions").'</td><td>';
print '<td>'.$langs->trans("PaymentMode").'</td><td>'. $facture->mode_reglement . '</td></tr>'; $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none");
print '</td>';
print '<td width="25%">'.$langs->trans("PaymentMode").'</td><td width="25%">';
$html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none");
print '</td></tr>';
print '<tr><td valign="top" colspan="4">'.$langs->trans("Note").' :</td></tr>'; print '<tr><td valign="top" colspan="4">'.$langs->trans("Note").' :</td></tr>';
print '<tr><td valign="top" colspan="4">'.($facture->note?nl2br($facture->note):"&nbsp;")."</td></tr>"; print '<tr><td valign="top" colspan="4">'.($fac->note?nl2br($fac->note):"&nbsp;")."</td></tr>";
if ($_GET["action"] == 'edit') if ($_GET["action"] == 'edit')
{ {
print '<form method="post" action="note.php?facid='.$facture->id.'">'; print '<form method="post" action="note.php?facid='.$fac->id.'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
print '<tr><td valign="top" colspan="4"><textarea name="note" cols="80" rows="8">'.$facture->note."</textarea></td></tr>"; print '<tr><td valign="top" colspan="4"><textarea name="note" cols="80" rows="8">'.$fac->note."</textarea></td></tr>";
print '<tr><td align="center" colspan="4"><input type="submit" value="'.$langs->trans("Save").'"></td></tr>'; print '<tr><td align="center" colspan="4"><input type="submit" value="'.$langs->trans("Save").'"></td></tr>';
print '</form>'; print '</form>';
} }
@ -139,7 +147,7 @@ if ($_GET["facid"])
if ($user->rights->facture->creer && $_GET["action"] <> 'edit') if ($user->rights->facture->creer && $_GET["action"] <> 'edit')
{ {
print "<a class=\"tabAction\" href=\"note.php?facid=$facture->id&amp;action=edit\">".$langs->trans('Edit')."</a>"; print "<a class=\"tabAction\" href=\"note.php?facid=$fac->id&amp;action=edit\">".$langs->trans('Edit')."</a>";
} }
print "</div>"; print "</div>";

View File

@ -19,7 +19,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -40,6 +39,18 @@ $langs->load("banks");
require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
// Sécurité accés client
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
/*
* Actions
*/
if ($_GET["action"] == "new") if ($_GET["action"] == "new")
{ {
$fact = new Facture($db); $fact = new Facture($db);
@ -66,14 +77,7 @@ if ($_GET["action"] == "delete")
} }
} }
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
llxHeader('',$langs->trans("Bill")); llxHeader('',$langs->trans("Bill"));
@ -100,16 +104,23 @@ if ($_GET["facid"] > 0)
$head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("CardBill"); $head[$h][1] = $langs->trans("CardBill");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Preview"); $head[$h][1] = $langs->trans("Preview");
$h++; $h++;
if ($fac->mode_reglement_code == 'PRE')
{
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("StandingOrders"); $head[$h][1] = $langs->trans("StandingOrders");
$hselected = $h; $hselected = $h;
$h++; $h++;
}
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Note"); $head[$h][1] = $langs->trans("Note");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id;
$head[$h][1] = $langs->trans("Info"); $head[$h][1] = $langs->trans("Info");
$h++; $h++;
@ -120,31 +131,42 @@ if ($_GET["facid"] > 0)
* Facture * Facture
*/ */
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Societe
print '<tr><td>'.$langs->trans("Company").'</td>'; print '<tr><td>'.$langs->trans("Company").'</td>';
print '<td colspan="3">'; print '<td colspan="5">';
print '<b><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>'; print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>';
print '</tr>';
print "<td>Conditions de réglement : " . $fac->cond_reglement ."</td></tr>";
// Dates
print '<tr><td>'.$langs->trans("Date").'</td>'; print '<tr><td>'.$langs->trans("Date").'</td>';
print "<td colspan=\"3\">".dolibarr_print_date($fac->date,"%A %d %B %Y")."</td>\n"; print '<td colspan="3">'.dolibarr_print_date($fac->date,"%A %d %B %Y").'</td>';
print '<td>'.$langs->trans("DateClosing").dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y").'</td></tr>'; print '<td>'.$langs->trans("DateClosing").'</td><td>' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y");
if ($fac->paye == 0 && $fac->date_lim_reglement < (time() - $warning_delay)) print img_warning($langs->trans("Late"));
print "</td></tr>";
print '<tr><td height="10">'.$langs->trans("Author").'</td><td colspan="4">'.$author->fullname.'</td></tr>'; // Conditions et modes de réglement
print '<tr><td>'.$langs->trans("PaymentConditions").'</td><td colspan="3">';
$html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none");
print '</td>';
print '<td width="25%">'.$langs->trans("PaymentMode").'</td><td width="25%">';
$html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none");
print '</td></tr>';
print '<tr><td height="10">'.$langs->trans("AmountHT").'</td>'; print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>'; print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td>&nbsp;</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td colspan="2">&nbsp;</td></tr>';
print '<tr><td height="10">'.$langs->trans("AmountTTC").'</td>'; print '<tr><td>'.$langs->trans("AmountTTC").'</td>';
print '<td align="right" colspan="2"><b>'.price($fac->total_ttc).'</b></td>'; print '<td align="right" colspan="2"><b>'.price($fac->total_ttc).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td>&nbsp;</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td colspan="2">&nbsp;</td></tr>';
print '<tr><td>RIB</td><td colspan="4">'; print '<tr><td>RIB</td><td colspan="5">';
print $soc->display_rib(); print $soc->display_rib();
print '</td></tr>'; print '</td></tr>';
print "</table>"; print '</table>';
print '</div>';
/* /*
* Demande de prélèvement * Demande de prélèvement
@ -172,7 +194,7 @@ if ($_GET["facid"] > 0)
print "<div class=\"tabsAction\">\n"; print "<div class=\"tabsAction\">\n";
// Valider // Valider
if ($fac->statut > 0 && $fac->paye == 0 && $fac->mode_reglement == 3 && $num == 0) if ($fac->statut > 0 && $fac->paye == 0 && $fac->mode_reglement_code == 'PRE' && $num == 0)
{ {
if ($user->rights->facture->creer) if ($user->rights->facture->creer)
{ {

View File

@ -55,8 +55,10 @@ class Facture
var $propalid; var $propalid;
var $projetid; var $projetid;
var $prefixe_facture; var $prefixe_facture;
var $cond_reglement; var $cond_reglement_id;
var $mode_reglement; var $cond_reglement_code;
var $mode_reglement_id;
var $mode_reglement_code;
/** /**
* \brief Constructeur de la classe * \brief Constructeur de la classe
@ -102,12 +104,17 @@ class Facture
$this->projetid = $_facrec->projetid; $this->projetid = $_facrec->projetid;
$this->cond_reglement = $_facrec->cond_reglement_id; $this->cond_reglement = $_facrec->cond_reglement_id;
$this->cond_reglement_id = $_facrec->cond_reglement_id;
$this->mode_reglement = $_facrec->mode_reglement_id;
$this->mode_reglement_id = $_facrec->mode_reglement_id;
$this->amount = $_facrec->amount; $this->amount = $_facrec->amount;
$this->remise = $_facrec->remise; $this->remise = $_facrec->remise;
$this->remise_percent = $_facrec->remise_percent; $this->remise_percent = $_facrec->remise_percent;
} }
$sql = "SELECT fdm,nbjour FROM ".MAIN_DB_PREFIX."cond_reglement WHERE rowid = $this->cond_reglement"; $sql = "SELECT fdm,nbjour ";
$sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
$sql.= " WHERE rowid = ".$this->cond_reglement;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if ($this->db->num_rows()) if ($this->db->num_rows())
@ -151,7 +158,7 @@ class Facture
$sql .= " VALUES ('$number','$socid', now(), '$totalht', '$remise'"; $sql .= " VALUES ('$number','$socid', now(), '$totalht', '$remise'";
$sql .= ",'$this->remise_percent', ".$this->db->idate($this->date); $sql .= ",'$this->remise_percent', ".$this->db->idate($this->date);
$sql .= ",'".addslashes($this->note)."',$user->id, $this->projetid"; $sql .= ",'".addslashes($this->note)."',$user->id, $this->projetid";
$sql .= ",".$this->cond_reglement.",".$this->mode_reglement.",".$this->db->idate($datelim).")"; $sql .= ",".$this->cond_reglement_id.",".$this->mode_reglement_id.",".$this->db->idate($datelim).")";
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture");
@ -654,7 +661,7 @@ class Facture
*/ */
function set_paiement_started($rowid) function set_paiement_started($rowid)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=2 WHERE rowid = $rowid ;"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=2 WHERE rowid = ".$rowid;
$return = $this->db->query( $sql); $return = $this->db->query( $sql);
} }
@ -664,7 +671,7 @@ class Facture
*/ */
function set_canceled($rowid) function set_canceled($rowid)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=3 WHERE rowid = $rowid ;"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_statut=3 WHERE rowid = ".$rowid;
$return = $this->db->query( $sql); $return = $this->db->query( $sql);
} }
@ -742,7 +749,9 @@ class Facture
{ {
$sql .= ", datef=now()"; $sql .= ", datef=now()";
// du coup, il faut aussi recalculer la date limite de règlement // du coup, il faut aussi recalculer la date limite de règlement
$sqltemp = "SELECT c.fdm,c.nbjour,c.rowid,f.fk_cond_reglement,f.rowid FROM ".MAIN_DB_PREFIX."cond_reglement as c, ".MAIN_DB_PREFIX."facture as f WHERE c.rowid=f.fk_cond_reglement AND f.rowid=$this->id"; $sqltemp = "SELECT c.fdm,c.nbjour,c.rowid,f.fk_cond_reglement,f.rowid";
$sqltemp.= " FROM ".MAIN_DB_PREFIX."cond_reglement as c, ".MAIN_DB_PREFIX."facture as f";
$sqltemp.= " WHERE c.rowid=f.fk_cond_reglement AND f.rowid=".$this->id;
if ($this->db->query($sqltemp)) if ($this->db->query($sqltemp))
{ {
if ($this->db->num_rows()) if ($this->db->num_rows())
@ -1350,33 +1359,71 @@ class Facture
} }
/** /**
* \brief Change le mode de réglement * \brief Change les conditions de réglement
* \param mode nouveau mode * \param cond_reglement_id Id des nouvelles conditions
* \return int >0 si ok, <0 si ko
*/ */
function mode_reglement($mode) function cond_reglement($cond_reglement_id)
{ {
//dolibarr_syslog("Facture::ModeReglement"); dolibarr_syslog("Facture::cond_reglement($cond_reglement_id)");
if ($this->statut > 0 && $this->paye == 0) if ($this->statut >= 0 && $this->paye == 0)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."facture"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture";
$sql .= " SET fk_mode_reglement = ".$mode; $sql .= " SET fk_cond_reglement = ".$cond_reglement_id;
$sql .= " WHERE rowid=".$this->id; $sql .= " WHERE rowid=".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$this->mode_reglement = $mode; $this->cond_reglement_id = $cond_reglement_id;
return 0; return 1;
} }
else else
{ {
dolibarr_syslog("Facture::mode_reglement Erreur -2"); dolibarr_syslog("Facture::cond_reglement Erreur $sql - ".$this->db->error());
$this->error=$this->db->error();
return -1;
}
}
else
{
dolibarr_syslog("Facture::cond_reglement, etat facture incompatible");
$this->error="Etat facture incompatible $this->statut $this->paye";
return -2; return -2;
} }
} }
/**
* \brief Change le mode de réglement
* \param mode Id du nouveau mode
* \return int >0 si ok, <0 si ko
*/
function mode_reglement($mode_reglement_id)
{
dolibarr_syslog("Facture::mode_reglement($mode_reglement_id)");
if ($this->statut >= 0 && $this->paye == 0)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture";
$sql .= " SET fk_mode_reglement = ".$mode_reglement_id;
$sql .= " WHERE rowid=".$this->id;
if ( $this->db->query($sql) )
{
$this->mode_reglement_id = $mode_reglement_id;
return 1;
}
else
{
dolibarr_syslog("Facture::mode_reglement Erreur $sql - ".$this->db->error());
$this->error=$this->db->error();
return -1;
}
}
else else
{ {
dolibarr_syslog("Facture::mode_reglement, etat facture incompatible"); dolibarr_syslog("Facture::mode_reglement, etat facture incompatible");
return -3; $this->error="Etat facture incompatible $this->statut $this->paye";
return -2;
} }
} }

View File

@ -491,11 +491,14 @@ class Form
/** /**
* \brief Charge dans cache la liste des conditions de paiements possibles * \brief Charge dans cache la liste des conditions de paiements possibles
* \return int Nb lignes chargées, 0 si déjà chargées, <0 si ko
*/ */
function load_cache_conditions_paiements() function load_cache_conditions_paiements()
{ {
global $langs; global $langs;
if (sizeof($this->cache_conditions_paiements_code)) return 0; // Cache déja chargé
dolibarr_syslog('html.form.class.php::load_cache_conditions_paiements'); dolibarr_syslog('html.form.class.php::load_cache_conditions_paiements');
$sql = "SELECT rowid, libelle"; $sql = "SELECT rowid, libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement"; $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
@ -526,11 +529,14 @@ class Form
/** /**
* \brief Charge dans cache la liste des types de paiements possibles * \brief Charge dans cache la liste des types de paiements possibles
* \return int Nb lignes chargées, 0 si déjà chargées, <0 si ko
*/ */
function load_cache_types_paiements() function load_cache_types_paiements()
{ {
global $langs; global $langs;
if (sizeof($this->cache_types_paiements_code)) return 0; // Cache déja chargé
dolibarr_syslog('html.form.class.php::load_cache_types_paiements'); dolibarr_syslog('html.form.class.php::load_cache_types_paiements');
$sql = "SELECT id, code, libelle, type"; $sql = "SELECT id, code, libelle, type";
$sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement";
@ -552,7 +558,7 @@ class Form
$this->cache_types_paiements_type[$obj->id]=$obj->type; $this->cache_types_paiements_type[$obj->id]=$obj->type;
$i++; $i++;
} }
return 1; return $num;
} }
else { else {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
@ -564,7 +570,7 @@ class Form
/** /**
* \brief Retourne la liste des types de paiements possibles * \brief Retourne la liste des types de paiements possibles
* \param selected Type de praiement présélectionné * \param selected Id du type de paiement présélectionné
* \param htmlname Nom de la zone select * \param htmlname Nom de la zone select
* \param filtertype Pour filtre * \param filtertype Pour filtre
*/ */
@ -572,16 +578,12 @@ class Form
{ {
global $langs; global $langs;
// Charge le cache si premier appel
if (! sizeof($this->cache_conditions_paiements_code))
{
$this->load_cache_conditions_paiements(); $this->load_cache_conditions_paiements();
}
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" name="'.$htmlname.'">';
foreach($this->cache_conditions_paiements_code as $id => $code) foreach($this->cache_conditions_paiements_code as $id => $code)
{ {
if ($selected == $code) if ($selected == $id)
{ {
print '<option value="'.$id.'" selected="true">'; print '<option value="'.$id.'" selected="true">';
} }
@ -599,8 +601,8 @@ class Form
/** /**
* \brief Retourne la liste des types de paiements possibles * \brief Retourne la liste des modes de paiements possibles
* \param selected Type de praiement présélectionné * \param selected Id du mode de paiement présélectionné
* \param htmlname Nom de la zone select * \param htmlname Nom de la zone select
* \param filtertype Pour filtre * \param filtertype Pour filtre
* \param format 0=id+libelle, 1=code+code * \param format 0=id+libelle, 1=code+code
@ -612,13 +614,8 @@ class Form
$filterarray=array(); $filterarray=array();
if ($filtertype && $filtertype != '-1') $filterarray=split(',',$filtertype); if ($filtertype && $filtertype != '-1') $filterarray=split(',',$filtertype);
// Charge le cache si premier appel
if (! sizeof($this->cache_types_paiements_code))
{
$this->load_cache_types_paiements(); $this->load_cache_types_paiements();
}
//dolibarr_syslog('html.form.class.php::select_types_paiements use cache');
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" name="'.$htmlname.'">';
foreach($this->cache_types_paiements_code as $id => $code) foreach($this->cache_types_paiements_code as $id => $code)
{ {
@ -627,10 +624,9 @@ class Form
if ($format == 0) print '<option value="'.$id.'"'; if ($format == 0) print '<option value="'.$id.'"';
if ($format == 1) print '<option value="'.$code.'"'; if ($format == 1) print '<option value="'.$code.'"';
if ($selected == $code) // Si selected est text, on compare avec code, sinon avec id
{ if (eregi('[a-z]', $selected) && $selected == $code) print ' selected="true"';
print ' selected="true"'; elseif ($selected == $id) print ' selected="true"';
}
print '>'; print '>';
if ($format == 0) print $this->cache_types_paiements_libelle[$id]; if ($format == 0) print $this->cache_types_paiements_libelle[$id];
if ($format == 1) print $code; if ($format == 1) print $code;
@ -966,7 +962,73 @@ class Form
} }
/** /**
* \brief Retourne la liste des devies, dans la langue de l'utilisateur * \brief Affiche formulaire de selection de conditions de paiement
* \param page Page
* \param selected Id condition présélectionnée
* \param htmlname Nom du formulaire select
*/
function form_conditions_reglement($page, $selected='', $htmlname='cond_reglement_id')
{
global $langs;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setconditions">';
print '<table class="noborder" cellpadding="0" cellspacing="0">';
print '<tr><td>';
$this->select_conditions_paiements($selected,$htmlname);
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>';
}
else
{
if ($selected)
{
$this->load_cache_conditions_paiements();
print $this->cache_conditions_paiements_libelle[$selected];
} else {
print "&nbsp;";
}
}
}
/**
* \brief Affiche formulaire de selection des modes de reglement
* \param page Page
* \param selected Id mode présélectionné
* \param htmlname Nom du formulaire select
*/
function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id')
{
global $langs;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setmode">';
print '<table class="noborder" cellpadding="0" cellspacing="0">';
print '<tr><td>';
$this->select_types_paiements($selected,$htmlname);
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>';
}
else
{
if ($selected)
{
$this->load_cache_types_paiements();
print $this->cache_types_paiements_libelle[$selected];
} else {
print "&nbsp;";
}
}
}
/**
* \brief Retourne la liste des devises, dans la langue de l'utilisateur
* \param selected code devise pré-sélectionnée * \param selected code devise pré-sélectionnée
* \param htmlname nom de la liste deroulante * \param htmlname nom de la liste deroulante
* \todo trier liste sur noms après traduction plutot que avant * \todo trier liste sur noms après traduction plutot que avant