Ajout filtre acces client

This commit is contained in:
Rodolphe Quiedeville 2003-03-23 15:53:03 +00:00
parent b26b2b979a
commit 07f0fd0a29
2 changed files with 534 additions and 465 deletions

View File

@ -1,8 +1,5 @@
<?PHP
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* $Id$
* $Source$
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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
@ -18,6 +15,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require("./pre.inc.php3");
require("../contact.class.php3");
@ -27,6 +27,16 @@ require("../actioncomm.class.php3");
llxHeader();
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
$db = new Db();
if ($sortorder == "") {
@ -73,51 +83,55 @@ if ($action=='add_action') {
}
if ($action == 'attribute_prefix') {
if ($action == 'attribute_prefix')
{
$societe = new Societe($db, $socid);
$societe->attribute_prefix($db, $socid);
}
if ($action == 'recontact') {
if ($action == 'recontact')
{
$dr = mktime(0, 0, 0, $remonth, $reday, $reyear);
$sql = "INSERT INTO llx_soc_recontact (fk_soc, datere, author) VALUES ($socid, $dr,'". $GLOBALS["REMOTE_USER"]."')";
$result = $db->query($sql);
}
if ($action == 'note') {
if ($action == 'note')
{
$sql = "UPDATE societe SET note='$note' WHERE idp=$socid";
$result = $db->query($sql);
}
if ($action == 'stcomm') {
if ($stcommid <> 'null' && $stcommid <> $oldstcomm) {
$sql = "INSERT INTO socstatutlog (datel, fk_soc, fk_statut, author) ";
$sql .= " VALUES ('$dateaction',$socid,$stcommid,'" . $GLOBALS["REMOTE_USER"] . "')";
$result = @$db->query($sql);
if ($result) {
$sql = "UPDATE societe SET fk_stcomm=$stcommid WHERE idp=$socid";
$result = $db->query($sql);
} else {
$errmesg = "ERREUR DE DATE !";
if ($action == 'stcomm')
{
if ($stcommid <> 'null' && $stcommid <> $oldstcomm)
{
$sql = "INSERT INTO socstatutlog (datel, fk_soc, fk_statut, author) ";
$sql .= " VALUES ('$dateaction',$socid,$stcommid,'" . $GLOBALS["REMOTE_USER"] . "')";
$result = @$db->query($sql);
if ($result)
{
$sql = "UPDATE societe SET fk_stcomm=$stcommid WHERE idp=$socid";
$result = $db->query($sql);
}
else
{
$errmesg = "ERREUR DE DATE !";
}
}
}
if ($actioncommid) {
$sql = "INSERT INTO actioncomm (datea, fk_action, fk_soc, fk_user_author) VALUES ('$dateaction',$actioncommid,$socid,'" . $user->id . "')";
$result = @$db->query($sql);
if (!$result) {
$errmesg = "ERREUR DE DATE !";
if ($actioncommid)
{
$sql = "INSERT INTO actioncomm (datea, fk_action, fk_soc, fk_user_author) VALUES ('$dateaction',$actioncommid,$socid,'" . $user->id . "')";
$result = @$db->query($sql);
if (!$result)
{
$errmesg = "ERREUR DE DATE !";
}
}
}
}
if ($page == -1) { $page = 0 ; }
$offset = $conf->liste_limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
/*
* Recherche
@ -139,53 +153,73 @@ if ($mode == 'search') {
}
}
if ($page == -1) { $page = 0 ; }
/*
* Mode Liste
*
*
*
*/
print_barre_liste("Liste des clients", $page, $PHP_SELF);
$offset = $conf->liste_limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
$sql = "SELECT s.idp, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, st.libelle as stcomm, s.prefix_comm FROM societe as s, c_stcomm as st WHERE s.fk_stcomm = st.id AND s.client=1";
if (strlen($stcomm)) {
$sql .= " AND s.fk_stcomm=$stcomm";
}
if (strlen($begin)) {
$sql .= " AND upper(s.nom) like '$begin%'";
}
/*
* Mode Liste
*
*
*
*/
print_barre_liste("Liste des clients", $page, $PHP_SELF);
if ($socname) {
$sql .= " AND lower(s.nom) like '%".strtolower($socname)."%'";
$sortfield = "lower(s.nom)";
$sortorder = "ASC";
}
$sql = "SELECT s.idp, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, st.libelle as stcomm, s.prefix_comm FROM societe as s, c_stcomm as st WHERE s.fk_stcomm = st.id AND s.client=1";
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit, $offset);
if (strlen($stcomm))
{
$sql .= " AND s.fk_stcomm=$stcomm";
}
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows();
$i = 0;
if (strlen($begin))
{
$sql .= " AND upper(s.nom) like '$begin%'";
}
if ($sortorder == "DESC") {
if ($user->societe_id)
{
$sql .= " AND s.idp = " .$user->societe_id;
}
if ($socname)
{
$sql .= " AND lower(s.nom) like '%".strtolower($socname)."%'";
$sortfield = "lower(s.nom)";
$sortorder = "ASC";
}
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit, $offset);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0;
if ($sortorder == "DESC")
{
$sortorder="ASC";
} else {
}
else
{
$sortorder="DESC";
}
print "<TABLE border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">";
print '<TR class="liste_titre">';
print "<TD valign=\"center\">";
print_liste_field_titre("Société",$PHP_SELF,"s.nom");
print "</td><TD>Ville</TD>";
print "<TD>email</TD>";
print "<TD align=\"center\">Statut</TD><td>&nbsp;</td><td colspan=\"2\">&nbsp;</td>";
print "</TR>\n";
$var=True;
while ($i < $num) {
print "<TABLE border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">";
print '<TR class="liste_titre">';
print "<TD valign=\"center\">";
print_liste_field_titre("Société",$PHP_SELF,"s.nom");
print "</td><TD>Ville</TD>";
print "<TD align=\"center\">Préfix</td><td colspan=\"2\">&nbsp;</td>";
print "</TR>\n";
$var=True;
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$var=!$var;
@ -193,23 +227,35 @@ if ($mode == 'search') {
print "<TR $bc[$var]>";
print "<TD><a href=\"fiche.php3?socid=$obj->idp\">$obj->nom</A></td>\n";
print "<TD>".$obj->ville."&nbsp;</TD>\n";
print "<TD>&nbsp;</TD>\n";
print "<TD align=\"center\">$obj->stcomm</TD>\n";
print "<TD align=\"center\">$obj->prefix_comm&nbsp;</TD>\n";
print "<TD align=\"center\"><a href=\"addpropal.php3?socidp=$obj->idp&action=create\">[Propal]</A></td>\n";
if ($conf->fichinter->enabled) {
print "<TD align=\"center\"><a href=\"../fichinter/fiche.php3?socidp=$obj->idp&action=create\">[Fiche Inter]</A></td>\n";
} else {
print "<TD>&nbsp;</TD>\n";
}
if ($user->societe_id == 0)
{
print "<TD align=\"center\"><a href=\"addpropal.php3?socidp=$obj->idp&action=create\">[Propal]</A></td>\n";
if ($conf->fichinter->enabled)
{
print "<TD align=\"center\"><a href=\"../fichinter/fiche.php3?socidp=$obj->idp&action=create\">[Fiche Inter]</A></td>\n";
}
else
{
print "<TD>&nbsp;</TD>\n";
}
}
else
{
print "<TD>&nbsp;</TD>\n";
print "<TD>&nbsp;</TD>\n";
}
print "</TR>\n";
$i++;
}
print "</TABLE>";
$db->free();
} else {
print $db->error() . ' ' . $sql;
}
print "</TABLE>";
$db->free();
}
else
{
print $db->error() . ' ' . $sql;
}
$db->close();

View File

@ -29,7 +29,18 @@ $db = new Db();
$yn[1] = "oui";
$yn[0] = "<b>non</b>";
/*
* Sécurité accés client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
/*
*
*/
if ($action == 'valid')
{
$fac = new Facture($db);
@ -75,7 +86,6 @@ if ($action == 'add')
if (! $propalid)
{
$facture = new Facture($db, $socid);
$facture->number = $facnumber;
$facture->date = $datefacture;
@ -89,7 +99,6 @@ if ($action == 'add')
}
else
{
$facture = new Facture($db, $socid);
$facture->number = $facnumber;
@ -107,8 +116,7 @@ if ($action == 'add')
}
}
$facid = $facid;
$action = '';
$action = '';
}
/*
*
@ -172,7 +180,6 @@ if ($action == 'send')
*
*
*/
if ($action == 'create')
{
print_titre("Emettre une facture");
@ -271,6 +278,11 @@ else
$sql = "SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.total, ".$db->pdate("f.datef")." as df, f.paye, f.fk_statut as statut, f.fk_user_author, f.note";
$sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.rowid = $facid";
if ($user->societe_id > 0)
{
$sql .= " AND s.idp = ".$user->societe_id;
}
$result = $db->query( $sql);
if ($result)
@ -287,288 +299,119 @@ else
print $db->error();
}
$soc = new Societe($db, $obj->socidp);
if ($num > 0)
{
$author = new User($db);
$author->id = $obj->fk_user_author;
$author->fetch();
$soc = new Societe($db, $obj->socidp);
print_titre("Facture : ".$obj->facnumber);
$author = new User($db);
$author->id = $obj->fk_user_author;
$author->fetch();
print_titre("Facture : ".$obj->facnumber);
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr><td width=\"50%\">";
/*
* Facture
*/
print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr><td>Client</td>";
print "<td colspan=\"3\">";
print "<b><a href=\"fiche.php3?socid=$obj->socidp\">$obj->socnom</a></b></td></tr>";
print "<tr><td>Date</td>";
print "<td colspan=\"3\">".strftime("%A %d %B %Y",$obj->df)."</td></tr>\n";
print "<tr><td>".translate("Author")."</td><td colspan=\"3\">$author->fullname</td>";
print '<tr><td>Montant</td>';
print '<td align="right" colspan="2"><b>'.price($obj->amount).'</b></td>';
print '<td>euros HT</td></tr>';
print '<tr><td>TVA</td><td align="right" colspan="2">'.tva($obj->amount).'</td>';
print '<td>euros</td></tr>';
print '<tr><td>Total</td><td align="right" colspan="2">'.price($obj->total).'</td>';
print '<td>euros TTC</td></tr>';
print '<tr><td>Statut</td><td align="center">'.$obj->statut.'</td>';
print "<td>".translate("Payed")."</td>";
print "<td align=\"center\" bgcolor=\"#f0f0f0\"><b>".$yn[$obj->paye]."</b></td></tr>";
print "</table>";
print "</td><td valign=\"top\">";
$_MONNAIE="euros";
/*
* Paiements
*/
$sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid";
$sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_facture = $facid AND p.fk_paiement = c.id";
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows();
$i = 0; $total = 0;
print "<p><b>Paiements</b>";
echo '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">';
print "<TR class=\"liste_titre\">";
print "<td>Date</td>";
print "<td>Type</td>";
print "<td align=\"right\">Montant</TD><td>&nbsp;</td>";
print "</TR>\n";
$var=True;
while ($i < $num) {
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD>".strftime("%d %B %Y",$objp->dp)."</TD>\n";
print "<TD>$objp->paiement_type $objp->num_paiement</TD>\n";
print "<TD align=\"right\">".price($objp->amount)."</TD><td>$_MONNAIE</td>\n";
print "</tr>";
$total = $total + $objp->amount;
$i++;
}
if ($obj->paye == 0) {
print "<tr><td colspan=\"2\" align=\"right\">Total :</td><td align=\"right\"><b>".price($total)."</b></td><td>$_MONNAIE</td></tr>\n";
print "<tr><td colspan=\"2\" align=\"right\">Facturé :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($obj->total)."</td><td bgcolor=\"#d0d0d0\">$_MONNAIE</td></tr>\n";
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr><td width=\"50%\">";
/*
* Facture
*/
print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";
print "<tr><td>Client</td>";
print "<td colspan=\"3\">";
print "<b><a href=\"fiche.php3?socid=$obj->socidp\">$obj->socnom</a></b></td></tr>";
$resteapayer = $obj->total - $total;
print "<tr><td colspan=\"2\" align=\"right\">Reste a payer :</td>";
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\">$_MONNAIE</td></tr>\n";
}
print "</table>";
$db->free();
} else {
print $db->error();
}
print "</td></tr>";
print "<tr><td>Note : ".nl2br($obj->note)."</td></tr>";
print "</table>";
/*
* Lignes de factures
*
*/
$sql = "SELECT l.description, l.price, l.qty, l.rowid";
$sql .= " FROM llx_facturedet as l WHERE l.fk_facture = $facid";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
echo '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">';
print "<TR class=\"liste_titre\">";
print '<td width="60%">Description</td>';
print '<td width="8%"align="center">Quantité</td>';
print '<td width="12%" align="right">Montant</TD><td width="10%">&nbsp;</td><td width="10%">&nbsp;</td>';
print "</TR>\n";
$var=True;
while ($i < $num) {
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD>".stripslashes(nl2br($objp->description))."</TD>\n";
print '<TD align="center">'.$objp->qty.'</TD>';
print '<TD align="right">'.price($objp->price)."</TD>\n";
if ($obj->statut == 0)
{
print '<td align="right"><a href="'.$PHPSELF.'?facid='.$facid.'&action=deleteline&rowid='.$objp->rowid.'">del</a></td>';
print '<td align="right"><a href="'.$PHPSELF.'?facid='.$facid.'&action=editline&rowid='.$objp->rowid.'">edit</a></td>';
}
else
{
print '<td>&nbsp;</td><td>&nbsp;</td>';
}
print "</tr>";
if ($action == 'editline' && $rowid == $objp->rowid)
{
print "<form action=\"$PHP_SELF?facid=$facid\" method=\"post\">";
print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
print "<TR $bc[$var]>";
print '<TD><textarea name="desc" cols="60" rows="3">'.stripslashes($objp->description).'</textarea></TD>';
print '<TD align="center"><input type="text" name="qty" value="'.$objp->qty.'"></TD>';
print '<TD align="right"><input type="text" name="price" value="'.price($objp->price).'"></TD>';
print '<td colspan="2"><input type="submit"></td>';
print '</tr>' . "\n";
print "</form>\n";
}
$total = $total + ($objp->qty * $objp->price);
$i++;
}
print "<tr><td>Date</td>";
print "<td colspan=\"3\">".strftime("%A %d %B %Y",$obj->df)."</td></tr>\n";
print "<tr><td>".translate("Author")."</td><td colspan=\"3\">$author->fullname</td>";
$db->free();
print '<tr><td>Montant</td>';
print '<td align="right" colspan="2"><b>'.price($obj->amount).'</b></td>';
print '<td>euros HT</td></tr>';
print '<tr><td>TVA</td><td align="right" colspan="2">'.tva($obj->amount).'</td>';
print '<td>euros</td></tr>';
print '<tr><td>Total</td><td align="right" colspan="2">'.price($obj->total).'</td>';
print '<td>euros TTC</td></tr>';
print '<tr><td>Statut</td><td align="center">'.$obj->statut.'</td>';
print "<td>".translate("Payed")."</td>";
print "<td align=\"center\" bgcolor=\"#f0f0f0\"><b>".$yn[$obj->paye]."</b></td></tr>";
print "</table>";
}
else
{
print $db->error();
}
print "</td><td valign=\"top\">";
/*
* Ajouter une ligne
*
*/
if ($obj->statut == 0)
{
print "<form action=\"$PHP_SELF?facid=$facid\" method=\"post\">";
echo '<TABLE border="1" width="100%" cellspacing="0" cellpadding="1">';
print "<TR class=\"liste_titre\">";
print "<td>Description</td>";
print "<td>Quantité</td>";
print "<td align=\"right\">Montant</TD>";
print "</TR>\n";
print '<input type="hidden" name="action" value="addligne">';
print '<tr><td><textarea name="desc" cols="60" rows="3"></textarea></td>';
print '<td><input type="text" name="qty" size="2"></td>';
print '<td><input type="text" name="pu" size="8"></td>';
print '</tr>';
print '<tr><td align="center" colspan="3"><input type="submit"></td></tr>';
print "</table>";
print "</form>";
}
$_MONNAIE="euros";
/*
* Fin Ajout ligne
*
*/
print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>";
if ($obj->statut == 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=delete\">Supprimer</a>]</td>";
}
elseif ($obj->statut == 1 && $resteapayer > 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=presend\">Envoyer</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>";
}
if ($obj->statut == 1 && $resteapayer > 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"paiement.php3?facid=$facid&action=create\">Emettre un paiement</a>]</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=\"$PHP_SELF?facid=$facid&action=payed\">Classer 'Payée'</a>]</td>";
}
else
{
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%\"><a href=\"facture.php3?facid=$facid&action=pdf\">Générer la facture</a></td>";
}
print "</tr></table><p>";
/*
* Documents générés
*
*/
print "<hr>";
print "<table width=\"100%\" cellspacing=2><tr><td width=\"60%\" valign=\"top\">";
print_titre("Documents générés");
print '<table width="100%" cellspacing="0" border="1" cellpadding="3">';
$file = $conf->facture->outputdir . "/" . $obj->facnumber . "/" . $obj->facnumber . ".pdf";
if (file_exists($file))
{
print "<tr $bc[0]><td>Facture PDF</a></td>";
print '<td><a href="'.$conf->facture->outputurl."/".$obj->facnumber."/".$obj->facnumber.'.pdf">'.$obj->facnumber.'.pdf</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
print '</tr>';
}
$file = $conf->facture->outputdir . "/" . $obj->facnumber . "/" . $obj->facnumber . ".ps";
if (file_exists($file))
{
print "<tr $bc[0]><td>Facture Postscript</a></td>";
print '<td><a href="'.$conf->facture->outputurl."/".$obj->facnumber."/".$obj->facnumber.'.ps">'.$obj->facnumber.'.ps</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
print '</tr>';
}
print '<tr $bc[0]><td colspan="4">(<a href="'.$conf->facture->outputurl.'/'.$facid.'/">liste...</a>)</td></tr>';
print "</table>\n";
print "</td>";
print '<td valign="top" width="40%">';
print_titre("Actions");
/*
* Liste des actions
*
*/
$sql = "SELECT ".$db->pdate("a.datea")." as da, a.note";
$sql .= " FROM actioncomm as a WHERE a.fk_soc = $obj->socidp AND a.fk_action = 9 AND a.fk_facture = $facid";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
if ($num)
/*
* Paiements
*/
$sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid";
$sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_facture = $facid AND p.fk_paiement = c.id";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
print '<TABLE border="1" cellspacing="0" cellpadding="4">';
print "<TR $bc[$var]>";
print "<p><b>Paiements</b>";
echo '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">';
print "<TR class=\"liste_titre\">";
print "<td>Date</td>";
print "<td>Action</td>";
print "<td>Type</td>";
print "<td align=\"right\">Montant</TD><td>&nbsp;</td>";
print "</TR>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD>".strftime("%d %B %Y",$objp->dp)."</TD>\n";
print "<TD>$objp->paiement_type $objp->num_paiement</TD>\n";
print "<TD align=\"right\">".price($objp->amount)."</TD><td>$_MONNAIE</td>\n";
print "</tr>";
$total = $total + $objp->amount;
$i++;
}
if ($obj->paye == 0)
{
print "<tr><td colspan=\"2\" align=\"right\">Total :</td><td align=\"right\"><b>".price($total)."</b></td><td>$_MONNAIE</td></tr>\n";
print "<tr><td colspan=\"2\" align=\"right\">Facturé :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($obj->total)."</td><td bgcolor=\"#d0d0d0\">$_MONNAIE</td></tr>\n";
$resteapayer = $obj->total - $total;
print "<tr><td colspan=\"2\" align=\"right\">Reste a payer :</td>";
print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td bgcolor=\"#f0f0f0\">$_MONNAIE</td></tr>\n";
}
print "</table>";
$db->free();
} else {
print $db->error();
}
print "</td></tr>";
print "<tr><td>Note : ".nl2br($obj->note)."</td></tr>";
print "</table>";
/*
* Lignes de factures
*
*/
$sql = "SELECT l.description, l.price, l.qty, l.rowid";
$sql .= " FROM llx_facturedet as l WHERE l.fk_facture = $facid";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
$i = 0; $total = 0;
echo '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">';
print "<TR class=\"liste_titre\">";
print '<td width="60%">Description</td>';
print '<td width="8%"align="center">Quantité</td>';
print '<td width="12%" align="right">Montant</TD><td width="10%">&nbsp;</td><td width="10%">&nbsp;</td>';
print "</TR>\n";
$var=True;
@ -577,125 +420,305 @@ else
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD>".strftime("%d %B %Y",$objp->da)."</TD>\n";
print '<TD align="right">'.stripslashes($objp->note).'</TD>';
print "<TD>".stripslashes(nl2br($objp->description))."</TD>\n";
print '<TD align="center">'.$objp->qty.'</TD>';
print '<TD align="right">'.price($objp->price)."</TD>\n";
if ($obj->statut == 0)
{
print '<td align="right"><a href="'.$PHPSELF.'?facid='.$facid.'&action=deleteline&rowid='.$objp->rowid.'">del</a></td>';
print '<td align="right"><a href="'.$PHPSELF.'?facid='.$facid.'&action=editline&rowid='.$objp->rowid.'">edit</a></td>';
}
else
{
print '<td>&nbsp;</td><td>&nbsp;</td>';
}
print "</tr>";
if ($action == 'editline' && $rowid == $objp->rowid)
{
print "<form action=\"$PHP_SELF?facid=$facid\" method=\"post\">";
print '<input type="hidden" name="action" value="updateligne">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
print "<TR $bc[$var]>";
print '<TD><textarea name="desc" cols="60" rows="3">'.stripslashes($objp->description).'</textarea></TD>';
print '<TD align="center"><input type="text" name="qty" value="'.$objp->qty.'"></TD>';
print '<TD align="right"><input type="text" name="price" value="'.price($objp->price).'"></TD>';
print '<td colspan="2"><input type="submit"></td>';
print '</tr>' . "\n";
print "</form>\n";
}
$total = $total + ($objp->qty * $objp->price);
$i++;
}
$db->free();
print "</table>";
}
else
{
print $db->error();
}
/*
* Ajouter une ligne
*
*/
if ($obj->statut == 0)
{
print "<form action=\"$PHP_SELF?facid=$facid\" method=\"post\">";
echo '<TABLE border="1" width="100%" cellspacing="0" cellpadding="1">';
print "<TR class=\"liste_titre\">";
print "<td>Description</td>";
print "<td>Quantité</td>";
print "<td align=\"right\">Montant</TD>";
print "</TR>\n";
print '<input type="hidden" name="action" value="addligne">';
print '<tr><td><textarea name="desc" cols="60" rows="3"></textarea></td>';
print '<td><input type="text" name="qty" size="2"></td>';
print '<td><input type="text" name="pu" size="8"></td>';
print '</tr>';
print '<tr><td align="center" colspan="3"><input type="submit"></td></tr>';
print "</table>";
print "</form>";
}
/*
* Fin Ajout ligne
*
*/
if ($user->societe_id == 0)
{
print "<p><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\"><tr>";
if ($obj->statut == 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=delete\">Supprimer</a>]</td>";
}
elseif ($obj->statut == 1 && $resteapayer > 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?facid=$facid&action=presend\">Envoyer</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>";
}
if ($obj->statut == 1 && $resteapayer > 0)
{
print "<td align=\"center\" width=\"25%\">[<a href=\"paiement.php3?facid=$facid&action=create\">Emettre un paiement</a>]</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=\"$PHP_SELF?facid=$facid&action=payed\">Classer 'Payée'</a>]</td>";
}
else
{
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%\"><a href=\"facture.php3?facid=$facid&action=pdf\">Générer la facture</a></td>";
}
print "</tr></table>";
}
print "<p>\n";
/*
* Documents générés
*
*/
print "<hr>";
print "<table width=\"100%\" cellspacing=2><tr><td width=\"60%\" valign=\"top\">";
print_titre("Documents générés");
print '<table width="100%" cellspacing="0" border="1" cellpadding="3">';
$file = $conf->facture->outputdir . "/" . $obj->facnumber . "/" . $obj->facnumber . ".pdf";
if (file_exists($file))
{
print "<tr $bc[0]><td>Facture PDF</a></td>";
print '<td><a href="'.$conf->facture->outputurl."/".$obj->facnumber."/".$obj->facnumber.'.pdf">'.$obj->facnumber.'.pdf</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
print '</tr>';
}
$file = $conf->facture->outputdir . "/" . $obj->facnumber . "/" . $obj->facnumber . ".ps";
if (file_exists($file))
{
print "<tr $bc[0]><td>Facture Postscript</a></td>";
print '<td><a href="'.$conf->facture->outputurl."/".$obj->facnumber."/".$obj->facnumber.'.ps">'.$obj->facnumber.'.ps</a></td>';
print '<td align="right">'.filesize($file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
print '</tr>';
}
print '<tr $bc[0]><td colspan="4">(<a href="'.$conf->facture->outputurl.'/'.$facid.'/">liste...</a>)</td></tr>';
print "</table>\n";
print "</td>";
print '<td valign="top" width="40%">';
print_titre("Actions");
/*
* Liste des actions
*
*/
$sql = "SELECT ".$db->pdate("a.datea")." as da, a.note";
$sql .= " FROM actioncomm as a WHERE a.fk_soc = $obj->socidp AND a.fk_action = 9 AND a.fk_facture = $facid";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
if ($num)
{
$i = 0; $total = 0;
print '<TABLE border="1" cellspacing="0" cellpadding="4">';
print "<TR $bc[$var]>";
print "<td>Date</td>";
print "<td>Action</td>";
print "</TR>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD>".strftime("%d %B %Y",$objp->da)."</TD>\n";
print '<TD align="right">'.stripslashes($objp->note).'</TD>';
print "</tr>";
$i++;
}
print "</table>";
}
}
else
{
print $db->error();
}
/*
*
*
*/
print "</td></tr>";
print "</table>";
/*
* Generation de la facture
*
*/
if ($action == 'pdf')
{
print "<hr><b>Génération de la facture</b><br><small><pre>";
$command = "export DBI_DSN=\"dbi:mysql:dbname=".$conf->db->name."\" ";
$command .= " ; ./texfacture.pl --html -vv --facture=$facid --pdf --output=".$conf->facture->outputdir;
$command .= " --templates=".$conf->facture->templatesdir;
$output = system($command);
print "<p>command :<br><small>$command</small><br>";
//print "<p>output :<br><small>$output</small><br>";
print "</pre></small>";
}
/*
*
*
*/
if ($action == 'presend')
{
$replytoname = "R. Quiedeville";
$from_name = $replytoname;
$replytomail = "rq@quiedeville.org";
$from_mail = $replytomail;
print "<form method=\"post\" action=\"$PHP_SELF?facid=$facid&action=send\">\n";
print "<input type=\"hidden\" name=\"replytoname\" value=\"$replytoname\">\n";
print "<input type=\"hidden\" name=\"replytomail\" value=\"$replytomail\">\n";
print "<p><b>Envoyer la facture par mail</b>";
print "<table cellspacing=0 border=1 cellpadding=3>";
print '<tr><td>Destinataire</td><td colspan="5">';
$form = new Form($db);
$form->select_array("destinataire",$soc->contact_email_array());
print '</td>';
print "<td><input size=\"30\" name=\"sendto\" value=\"$obj->email\"></td></tr>";
print "<tr><td>Expéditeur</td><td colspan=\"5\">$from_name</td><td>$from_mail</td></tr>";
print "<tr><td>Reply-to</td><td colspan=\"5\">$replytoname</td>";
print "<td>$replytomail</td></tr>";
print "</table>";
print "<input type=\"submit\" value=\"Envoyer\">";
print "</form>";
}
/*
* Propales
*/
$sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid";
$sql .= " FROM llx_propal as p, llx_fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $facid";
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows();
if ($num)
{
$i = 0; $total = 0;
print "<p><b>Proposition(s) commerciale(s) associée(s)</b>";
print '<TABLE border="1" width="100%" cellspacing="0" cellpadding="4">';
print "<TR class=\"liste_titre\">";
print "<td>Num</td>";
print "<td>Date</td>";
print "<td align=\"right\">Prix</TD>";
print "</TR>\n";
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD><a href=\"propal.php3?propalid=$objp->propalid\">$objp->ref</a></TD>\n";
print "<TD>".strftime("%d %B %Y",$objp->dp)."</TD>\n";
print '<TD align="right">'.price($objp->price).'</TD>';
print "</tr>";
$total = $total + $objp->price;
$i++;
}
print "<tr><td align=\"right\" colspan=\"3\">Total : <b>".price($total)."</b> $_MONNAIE HT</td></tr>\n";
print "</table>";
}
} else {
print $db->error();
}
}
else
{
print $db->error();
/* Facture non trouvée */
print "Facture inexistante ou accés refusé";
}
/*
*
*
*/
print "</td></tr>";
print "</table>";
/*
* Generation de la facture
*
*/
if ($action == 'pdf')
{
print "<hr><b>Génération de la facture</b><br><small><pre>";
$command = "export DBI_DSN=\"dbi:mysql:dbname=".$conf->db->name."\" ";
$command .= " ; ./texfacture.pl --html -vv --facture=$facid --pdf --output=".$conf->facture->outputdir;
$command .= " --templates=".$conf->facture->templatesdir;
$output = system($command);
print "<p>command :<br><small>$command</small><br>";
//print "<p>output :<br><small>$output</small><br>";
print "</pre></small>";
}
/*
*
*
*/
if ($action == 'presend')
{
$replytoname = "R. Quiedeville";
$from_name = $replytoname;
$replytomail = "rq@quiedeville.org";
$from_mail = $replytomail;
print "<form method=\"post\" action=\"$PHP_SELF?facid=$facid&action=send\">\n";
print "<input type=\"hidden\" name=\"replytoname\" value=\"$replytoname\">\n";
print "<input type=\"hidden\" name=\"replytomail\" value=\"$replytomail\">\n";
print "<p><b>Envoyer la facture par mail</b>";
print "<table cellspacing=0 border=1 cellpadding=3>";
print '<tr><td>Destinataire</td><td colspan="5">';
$form = new Form($db);
$form->select_array("destinataire",$soc->contact_email_array());
print '</td>';
print "<td><input size=\"30\" name=\"sendto\" value=\"$obj->email\"></td></tr>";
print "<tr><td>Expéditeur</td><td colspan=\"5\">$from_name</td><td>$from_mail</td></tr>";
print "<tr><td>Reply-to</td><td colspan=\"5\">$replytoname</td>";
print "<td>$replytomail</td></tr>";
print "</table>";
print "<input type=\"submit\" value=\"Envoyer\">";
print "</form>";
}
/*
*
*
*/
/*
* Propales
*/
$sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid";
$sql .= " FROM llx_propal as p, llx_fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $facid";
$result = $db->query($sql);
if ($result) {
$num = $db->num_rows();
if ($num) {
$i = 0; $total = 0;
print "<p><b>Proposition(s) commerciale(s) associée(s)</b>";
print '<TABLE border="1" width="100%" cellspacing="0" cellpadding="4">';
print "<TR class=\"liste_titre\">";
print "<td>Num</td>";
print "<td>Date</td>";
print "<td align=\"right\">Prix</TD>";
print "</TR>\n";
$var=True;
while ($i < $num) {
$objp = $db->fetch_object( $i);
$var=!$var;
print "<TR $bc[$var]>";
print "<TD><a href=\"propal.php3?propalid=$objp->propalid\">$objp->ref</a></TD>\n";
print "<TD>".strftime("%d %B %Y",$objp->dp)."</TD>\n";
print '<TD align="right">'.price($objp->price).'</TD>';
print "</tr>";
$total = $total + $objp->price;
$i++;
}
print "<tr><td align=\"right\" colspan=\"3\">Total : <b>".price($total)."</b> $_MONNAIE HT</td></tr>\n";
print "</table>";
}
} else {
print $db->error();
}
} else {
/*
*
* Liste
* Mode Liste
*
*
*/