Gestion du mode d'edition

This commit is contained in:
Rodolphe Quiedeville 2003-01-30 18:16:54 +00:00
parent 476614432b
commit 57c4518cb8

View File

@ -1,5 +1,5 @@
<?PHP <?PHP
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* *
* 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
@ -28,22 +28,45 @@ $db = new Db();
$yn[1] = "oui"; $yn[1] = "oui";
$yn[0] = "<b>non</b>"; $yn[0] = "<b>non</b>";
if ($action == 'valid') { if ($action == 'valid')
{
$sql = "UPDATE llx_facture_fourn set fk_statut = 1 WHERE rowid = $facid ;"; $sql = "UPDATE llx_facture_fourn set fk_statut = 1 WHERE rowid = $facid ;";
$result = $db->query( $sql); $result = $db->query( $sql);
} }
if ($action == 'payed') { if ($action == 'payed')
{
$sql = "UPDATE llx_facture_fourn set paye = 1 WHERE rowid = $facid ;"; $sql = "UPDATE llx_facture_fourn set paye = 1 WHERE rowid = $facid ;";
$result = $db->query( $sql); $result = $db->query( $sql);
} }
if ($action == 'update')
{
$tva = ($HTTP_POST_VARS["tva_taux"] * $HTTP_POST_VARS["amount"]) / 100 ;
$remise = 0;
$total = $tva + $amount ;
$datefacture = $db->idate(mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"]));
$sql = "UPDATE llx_facture_fourn set ";
$sql .= " libelle='".$HTTP_POST_VARS["libelle"]."'";
$sql .= ", note='".$HTTP_POST_VARS["note"]."'";
$sql .= ", datef = '$datefacture'";
$sql .= ", amount=".$HTTP_POST_VARS["amount"];
$sql .= ", total = $total";
$sql .= ", tva = $tva";
$sql .= " WHERE rowid = $facid ;";
$result = $db->query( $sql);
}
if ($action == 'add') { if ($action == 'add')
{
$datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear)); $datefacture = $db->idate(mktime(12, 0 , 0, $pmonth, $pday, $pyear));
$tva = 0;
$tva = ($tva_taux * $amount) / 100 ; $tva = ($tva_taux * $amount) / 100 ;
$remise = 0; $remise = 0;
$total = $tva + $amount ; $total = $tva + $amount ;
@ -52,20 +75,24 @@ if ($action == 'add') {
$sql .= " VALUES ('$facnumber','$libelle', $socidp, now(), $datefacture,'$note', $amount, $remise, $tva, $total, $user->id);"; $sql .= " VALUES ('$facnumber','$libelle', $socidp, now(), $datefacture,'$note', $amount, $remise, $tva, $total, $user->id);";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) { if ($result)
$sql = "SELECT rowid, facnumber FROM llx_facture_fourn WHERE facnumber='$facnumber';"; {
$result = $db->query($sql); $sql = "SELECT rowid, facnumber FROM llx_facture_fourn WHERE facnumber='$facnumber';";
if ($result) { $result = $db->query($sql);
$objfac = $db->fetch_object( 0); if ($result)
$facid = $objfac->rowid; {
$facnumber = $objfac->facnumber; $objfac = $db->fetch_object( 0);
$action = ''; $facid = $objfac->rowid;
$facnumber = $objfac->facnumber;
$action = '';
}
}
else
{
print "<p><b>Erreur : la facture n'a pas été créée !</b>$sql<br>". $db->error();
print "<p>Retour à la <a href=\"propal.php3?propalid=$propalid\">propal</a>";
} }
} else {
print "<p><b>Erreur : la facture n'a pas été créée, vérifier le numéro !</b>$sql<br>". $db->error();
print "<p>Retour à la <a href=\"propal.php3?propalid=$propalid\">propal</a>";
}
$facid = $facid; $facid = $facid;
$action = ''; $action = '';
@ -78,10 +105,10 @@ if ($action == 'add') {
* *
*/ */
if ($action == 'create') { if ($action == 'create')
{
print_titre("Emettre une facture"); print_titre("Emettre une facture");
print "<form action=\"$PHP_SELF\" method=\"post\">"; print "<form action=\"$PHP_SELF\" method=\"post\">";
print '<table cellspacing="0" border="1" width="100%">'; print '<table cellspacing="0" border="1" width="100%">';
print "<tr bgcolor=\"#e0e0e0\"><td>Société :</td>"; print "<tr bgcolor=\"#e0e0e0\"><td>Société :</td>";
@ -91,21 +118,26 @@ if ($action == 'create') {
$sql = "SELECT s.nom, s.prefix_comm, s.idp"; $sql = "SELECT s.nom, s.prefix_comm, s.idp";
$sql .= " FROM societe as s WHERE s.fournisseur = 1 ORDER BY s.nom ASC"; $sql .= " FROM societe as s WHERE s.fournisseur = 1 ORDER BY s.nom ASC";
if ( $db->query($sql) ) { if ( $db->query($sql) )
$num = $db->num_rows(); {
$i = 0; $num = $db->num_rows();
while ($i < $num) { $i = 0;
$obj = $db->fetch_object($i); while ($i < $num)
print '<option value="'.$obj->idp; {
$obj = $db->fetch_object($i);
print '<option value="'.$obj->idp;
if ($socid == $obj->idp) { if ($socid == $obj->idp)
print '" SELECTED>'.$obj->nom.'</option>'; {
} else { print '" SELECTED>'.$obj->nom.'</option>';
print '">'.$obj->nom.'</option>'; }
} else
$i++; {
print '">'.$obj->nom.'</option>';
}
$i++;
}
} }
}
print '</select></td>'; print '</select></td>';
print "<td rowspan=6>Commentaires :<br>"; print "<td rowspan=6>Commentaires :<br>";
print "<textarea name=\"note\" wrap=\"soft\" cols=\"30\" rows=\"15\"></textarea></td></tr>"; print "<textarea name=\"note\" wrap=\"soft\" cols=\"30\" rows=\"15\"></textarea></td></tr>";
@ -133,23 +165,31 @@ if ($action == 'create') {
print "<tr><td>Date :</td><td>"; print "<tr><td>Date :</td><td>";
$cday = date("d", time()); $cday = date("d", time());
print "<select name=\"pday\">"; print "<select name=\"pday\">";
for ($day = 1 ; $day < $sday + 32 ; $day++) { for ($day = 1 ; $day < $sday + 32 ; $day++)
if ($day == $cday) { {
print "<option value=\"$day\" SELECTED>$day"; if ($day == $cday)
} else { {
print "<option value=\"$day\">$day"; print "<option value=\"$day\" SELECTED>$day";
}
else
{
print "<option value=\"$day\">$day";
}
} }
}
print "</select>"; print "</select>";
$cmonth = date("n", time()); $cmonth = date("n", time());
print "<select name=\"pmonth\">"; print "<select name=\"pmonth\">";
for ($month = 1 ; $month <= 12 ; $month++) { for ($month = 1 ; $month <= 12 ; $month++)
if ($month == $cmonth) { {
print "<option value=\"$month\" SELECTED>" . $strmonth[$month]; if ($month == $cmonth)
} else { {
print "<option value=\"$month\" SELECTED>" . $strmonth[$month];
}
else
{
print "<option value=\"$month\">" . $strmonth[$month]; print "<option value=\"$month\">" . $strmonth[$month];
}
} }
}
print "</select>"; print "</select>";
print "<select name=\"pyear\">"; print "<select name=\"pyear\">";
@ -157,9 +197,10 @@ if ($action == 'create') {
print "<option value=\"".($syear-1)."\">".($syear-1); print "<option value=\"".($syear-1)."\">".($syear-1);
print "<option value=\"$syear\" SELECTED>$syear"; print "<option value=\"$syear\" SELECTED>$syear";
for ($year = $syear +1 ; $year < $syear + 5 ; $year++) { for ($year = $syear +1 ; $year < $syear + 5 ; $year++)
print "<option value=\"$year\">$year"; {
} print "<option value=\"$year\">$year";
}
print "</select></td></tr>"; print "</select></td></tr>";
$author = $GLOBALS["REMOTE_USER"]; $author = $GLOBALS["REMOTE_USER"];
print "<input type=\"hidden\" name=\"author\" value=\"$author\">"; print "<input type=\"hidden\" name=\"author\" value=\"$author\">";
@ -169,14 +210,17 @@ if ($action == 'create') {
print "</form>"; print "</form>";
print "</table>"; print "</table>";
} else { }
else
{
if ($facid > 0) { if ($facid > 0)
{
$sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.tva, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.note, f.libelle"; $sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.tva, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.note, f.libelle, f.rowid";
$sql .= " FROM societe as s,llx_facture_fourn as f WHERE f.fk_soc = s.idp AND f.rowid = $facid"; $sql .= " FROM societe as s,llx_facture_fourn as f WHERE f.fk_soc = s.idp AND f.rowid = $facid";
$result = $db->query( $sql); $result = $db->query( $sql);
if ($result) { if ($result) {
$num = $db->num_rows(); $num = $db->num_rows();
@ -188,6 +232,60 @@ if ($action == 'create') {
print $db->error(); print $db->error();
} }
/*
* Edition
*
*
*/
if ($action == "edit")
{
print "<form action=\"$PHP_SELF?facid=$obj->rowid\" method=\"post\">";
print '<input type="hidden" name="action" value="update">';
print '<table cellspacing="0" border="1" width="100%">';
print "<tr bgcolor=\"#e0e0e0\"><td>Société :</td>";
print '<td>'.stripslashes($obj->socnom);
print '</td>';
print '<td rowspan="6">Commentaires :<br>';
print '<textarea name="note" wrap="soft" cols="30" rows="15">';
print stripslashes($obj->note);
print '</textarea></td></tr>';
print '<tr><td>Numéro :</td><td><input name="facnumber" type="text" value="'.$obj->facnumber.'"></td></tr>';
print '<tr><td>Libellé :</td><td><input size="30" name="libelle" type="text" value="'.stripslashes($obj->libelle).'"></td></tr>';
print '<tr bgcolor="#e0e0e0"><td>Montant HT :</td>';
print '<td><input type="text" size="8" name="amount" value="'.$obj->amount.'"></td></tr>';
print '<tr bgcolor="#e0e0e0"><td>TVA :</td>';
print '<td><select name="tva_taux">';
print '<option value="19.6">19.6';
print '<option value="5.5">5.5';
print '<option value="0">0';
print '</select></td></tr>';
print "<tr><td>Date :</td><td>";
print_date_select($obj->df);
print "</td></tr>";
print "<tr><td>Auteur :</td><td>".$user->fullname."</td></tr>";
print "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" value=\"Enregistrer\"></td></tr>";
print "</form>";
print "</table>";
}
/*
* Affichage
*
*
*/
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">"; print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr>"; print "<tr>";
print '<td><div class="titre">Facture : '.$obj->facnumber.'</div></td>'; print '<td><div class="titre">Facture : '.$obj->facnumber.'</div></td>';
@ -198,7 +296,10 @@ if ($action == 'create') {
* Facture * Facture
*/ */
print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">"; print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr><td>Société</td><td colspan=\"3\"><b><a href=\"fiche.php3?socid=$obj->socidp\">$obj->socnom</a></b></td></tr>"; print "<tr><td>Société</td><td colspan=\"3\"><b><a href=\"fiche.php3?socid=$obj->socidp\">$obj->socnom</a></b></td>";
print "<tr><td>Date</td><td colspan=\"3\">".strftime("%A %d %B %Y",$obj->df)."</td></tr>\n"; print "<tr><td>Date</td><td colspan=\"3\">".strftime("%A %d %B %Y",$obj->df)."</td></tr>\n";
print "<tr><td>Libelle</td><td colspan=\"3\">$obj->libelle</td>"; print "<tr><td>Libelle</td><td colspan=\"3\">$obj->libelle</td>";
@ -216,6 +317,9 @@ if ($action == 'create') {
print "</td><td valign=\"top\">"; print "</td><td valign=\"top\">";
print nl2br(stripslashes($obj->note));
$_MONNAIE="euros"; $_MONNAIE="euros";
/* /*
@ -264,31 +368,41 @@ if ($action == 'create') {
} }
print "</td></tr>"; print "</td></tr>";
print "<tr><td>Note : ".nl2br($obj->note)."</td></tr>";
print "</table>"; print "</table>";
print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>"; print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>";
if ($obj->statut == 0) { if ($obj->statut == 0)
print '<td align="center" bgcolor="#e0e0e0" width="25%">[<a href="index.php3?facid='.$facid.'&action=delete">'.translate("Delete").'</a>]</td>'; {
} else { print '<td align="center" bgcolor="#e0e0e0" width="25%">[<a href="index.php3?facid='.$facid.'&action=delete">'.translate("Delete").'</a>]</td>';
print "<td align=\"center\" width=\"25%\">-</td>"; }
} else
if ($obj->statut == 1 && $resteapayer > 0) { {
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"paiement.php3?facid=$facid&action=create\">Emettre un paiement</a>]</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} else { }
print "<td align=\"center\" width=\"25%\">-</td>";
}
if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0) { print '<td align="center" width="25%">[<a href="fiche.php3?facid='.$obj->rowid.'&action=edit">Editer</a>]</td>';
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=payed\">Classer 'Payée'</a>]</td>";
} else { if ($obj->statut == 1 && abs($resteapayer == 0) && $obj->paye == 0)
print "<td align=\"center\" width=\"25%\">-</td>"; {
} print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=payed\">Classer 'Payée'</a>]</td>";
if ($obj->statut == 0) { }
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=valid\">Valider</a>]</td>"; else
} else { {
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
if ($obj->statut == 0)
{
print "<td align=\"center\" bgcolor=\"#e0e0e0\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=valid\">Valider</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>";
}
print "</tr></table><p>"; print "</tr></table><p>";
/* /*