Gestion des modififs de produits

This commit is contained in:
Rodolphe Quiedeville 2003-06-20 09:50:11 +00:00
parent c33d04534b
commit 5286ca8a7e

View File

@ -55,7 +55,7 @@ if ($action == 'add')
$propal = new Propal($db, $socidp); $propal = new Propal($db, $socidp);
$propal->remise = $remise; $propal->remise = $remise;
$propal->datep = $db->idate(mktime(12, 1 , 1, $pmonth, $pday, $pyear)); $propal->datep = $db->idate(mktime(12, 1 , 1, $remonth, $reday, $reyear));
$propal->contactid = $contactidp; $propal->contactid = $contactidp;
$propal->projetidp = $projetidp; $propal->projetidp = $projetidp;
@ -104,7 +104,32 @@ if ($action == 'setstatut')
$propal->cloture($user->id, $statut, $note); $propal->cloture($user->id, $statut, $note);
} }
elseif ( $action == 'delete' )
if ($HTTP_POST_VARS["action"] == 'addligne')
{
/*
* Ajout d'une ligne produit dans la propale
*/
if ($HTTP_POST_VARS["idprod"])
{
$propal = new Propal($db);
$propal->id = $propalid;
$propal->insert_product($HTTP_POST_VARS["idprod"], $HTTP_POST_VARS["qty"]);
}
}
if ($action == 'del_ligne')
{
/*
* Supprime une ligne produit dans la propale
*/
$propal = new Propal($db);
$propal->id = $propalid;
$propal->delete_product($ligne);
}
if ( $action == 'delete' )
{ {
$sql = "DELETE FROM llx_propal WHERE rowid = $propalid;"; $sql = "DELETE FROM llx_propal WHERE rowid = $propalid;";
if ( $db->query($sql) ) if ( $db->query($sql) )
@ -243,23 +268,30 @@ if ($propalid) {
} }
print "<table width=\"100%\" cellspacing=2><tr><td valign=\"top\">";
/* /*
* Produits * Produits
*/ */
$sql = "SELECT p.label as product, p.ref, pt.price, pt.qty"; print_titre("Produits");
print '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">';
print "<TR class=\"liste_titre\">";
print "<td>Réf</td><td>Produit</td>";
print "<td align=\"right\">Prix</TD><td align=\"center\">Qté.</td>";
if ($obj->statut == 0)
{
print "<td>&nbsp;</td>";
}
print "</TR>\n";
$sql = "SELECT pt.rowid,p.label as product, p.ref, pt.price, pt.qty";
$sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$num = $db->num_rows(); $num = $db->num_rows();
$i = 0; $total = 0; $i = 0;
print "<p><b>Produits</b><TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">";
print "<TR class=\"liste_titre\">";
print "<td>Réf</td><td>Produit</td>";
print "<td align=\"right\">Prix</TD><td align=\"center\">Qté.</td>";
print "</TR>\n";
$var=True; $var=True;
@ -271,54 +303,109 @@ if ($propalid) {
print "<TD>[$objp->ref]</TD>\n"; print "<TD>[$objp->ref]</TD>\n";
print "<TD>$objp->product</TD>\n"; print "<TD>$objp->product</TD>\n";
print "<TD align=\"right\">".price($objp->price)."</TD><td align=\"center\">".$objp->qty."</td>\n"; print "<TD align=\"right\">".price($objp->price)."</TD><td align=\"center\">".$objp->qty."</td>\n";
if ($obj->statut == 0)
{
print '<td align="center"><a href="propal.php3?propalid='.$propalid.'&ligne='.$objp->rowid.'&action=del_ligne">Supprimer</a></td>';
}
print "</tr>"; print "</tr>";
$total = $total + $objp->price;
$i++; $i++;
} }
print "</table>";
} }
/* if ($obj->statut == 0)
* {
*/
print "</td></tr>"; $sql = "SELECT p.rowid,p.label,p.ref,p.price FROM llx_product as p ORDER BY p.ref";
if ( $db->query($sql) )
{
$opt = "<option value=\"0\" SELECTED></option>";
if ($result)
{
$num = $db->num_rows(); $i = 0;
while ($i < $num)
{
$objp = $db->fetch_object( $i);
$opt .= "<option value=\"$objp->rowid\">[$objp->ref] $objp->label : $objp->price</option>\n";
$i++;
}
}
$db->free();
}
else
{
print $db->error();
}
print '<form action="propal.php3?propalid='.$propalid.'" method="post">';
print '<input type="hidden" name="action" value="addligne">';
print "<tr><td colspan=\"2\"><select name=\"idprod\">$opt</select></td>";
print '<td><input type="text" size="3" name="qty" value="1"></td>';
print '<td><input type="submit" value="Ajouter"></td>';
print "</tr>\n";
print '</form>';
}
print "</table>"; print "</table>";
/* /*
* Actions * Actions
*/ */
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 bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?propalid=$propalid&action=delete\">Supprimer</a>]</td>"; print "<td bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?propalid=$propalid&action=delete\">Supprimer</a>]</td>";
} else { }
if ($obj->statut == 1) { else
{
if ($obj->statut == 1)
{
print "<td bgcolor=\"#e0e0e0\" align=center>[<a href=\"$PHP_SELF?propalid=$propalid&action=statut\">Cloturer</a>]</td>"; print "<td bgcolor=\"#e0e0e0\" align=center>[<a href=\"$PHP_SELF?propalid=$propalid&action=statut\">Cloturer</a>]</td>";
} else { }
else
{
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
} }
/* /*
* *
*/ */
if ($obj->statut < 2)
{
print '<td align="center" width="25%">[<a href="'.$PHP_SELF."?propalid=$propalid&action=pdf\">Générer</a>]</td>"; print '<td align="center" width="25%">[<a href="'.$PHP_SELF."?propalid=$propalid&action=pdf\">Générer</a>]</td>";
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>";
}
/* /*
* *
*/ */
if ($obj->statut == 1) { if ($obj->statut == 1)
$file = $conf->propal->outputdir. "/$obj->ref/$obj->ref.pdf"; {
if (file_exists($file)) { $file = PROPALE_OUTPUTDIR. "/$obj->ref/$obj->ref.pdf";
if (file_exists($file))
{
print "<td bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">"; print "<td bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">";
print "[<a href=\"$PHP_SELF?propalid=$propalid&action=presend\">Envoyer la propale par mail</a>]</td>"; print "[<a href=\"$PHP_SELF?propalid=$propalid&action=presend\">Envoyer la proposition</a>]</td>";
} else {
print "<td bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">! Propale non generee !</td>";
} }
} else { else
{
print '<td bgcolor="#e0e0e0" align="center" width="25%">! Propale non generee !</td>';
}
}
else
{
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
if ($obj->statut == 0) { if ($obj->statut == 0)
{
print "<td bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?propalid=$propalid&valid=1\">Valider</a>]</td>"; print "<td bgcolor=\"#e0e0e0\" align=\"center\" width=\"25%\">[<a href=\"$PHP_SELF?propalid=$propalid&valid=1\">Valider</a>]</td>";
} else { }
else
{
print "<td align=\"center\" width=\"25%\">-</td>"; print "<td align=\"center\" width=\"25%\">-</td>";
} }
print "</tr></table>"; print "</tr></table>";
@ -330,9 +417,11 @@ if ($propalid) {
* Send * Send
* *
*/ */
if ($action == 'send') { if ($action == 'send')
$file = $GLOBALS["GLJ_ROOT"] . "/www-sys/doc/propal/$obj->ref/$obj->ref.pdf"; {
if (file_exists($file)) { $file = PROPALE_OUTPUTDIR . "/$obj->ref/$obj->ref.pdf";
if (file_exists($file))
{
$subject = "Notre proposition commerciale $obj->ref"; $subject = "Notre proposition commerciale $obj->ref";
$message = "Veuillez trouver ci-joint notre proposition commerciale $obj->ref\n\nCordialement\n\n"; $message = "Veuillez trouver ci-joint notre proposition commerciale $obj->ref\n\nCordialement\n\n";
@ -344,11 +433,14 @@ if ($propalid) {
$mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype, $filename); $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype, $filename);
if ( $mailfile->sendfile() ) { if ( $mailfile->sendfile() )
{
print "<p>envoy&eacute; &agrave; $sendto"; print "<p>envoy&eacute; &agrave; $sendto";
print "<p>envoy&eacute; par ".htmlentities($replyto); print "<p>envoy&eacute; par ".htmlentities($replyto);
} else { }
else
{
print "<b>!! erreur d'envoi"; print "<b>!! erreur d'envoi";
} }
} }
@ -358,30 +450,35 @@ if ($propalid) {
* Ne fonctionne pas, a corriger ! * Ne fonctionne pas, a corriger !
*/ */
if ( $db->query($sql) ) { if ( $db->query($sql) )
{
$sql = "INSERT INTO llx_actioncomm (datea,fk_action,fk_soc, propalrowid,note, fk_user_author) "; $sql = "INSERT INTO llx_actioncomm (datea,fk_action,fk_soc, propalrowid,note, fk_user_author) ";
$sql .= " VALUES (now(), 3, $obj->idp, $propalid, 'Envoyée à $sendto',$user->id);"; $sql .= " VALUES (now(), 3, $obj->idp, $propalid, 'Envoyée à $sendto',$user->id);";
if (! $db->query($sql) ) { if (! $db->query($sql) ) {
print $db->error(); print $db->error();
print "<p>$sql</p>"; print "<p>$sql</p>";
} }
} else { }
else
{
print $db->error(); print $db->error();
} }
} }
/* /*
* *
*/ */
print "<hr>";
print "<table width=\"100%\" cellspacing=2><tr><td width=\"50%\" valign=\"top\">"; print "<table width=\"100%\" cellspacing=2><tr><td width=\"50%\" valign=\"top\">";
print "<b>Documents générés</b><br>"; print_titre("Documents générés");
print "<table width=\"100%\" cellspacing=0 border=1 cellpadding=3>"; print "<table width=\"100%\" cellspacing=0 border=1 cellpadding=3>";
$file = PROPALE_OUTPUTDIR . "/$obj->ref/$obj->ref.pdf"; $file = PROPALE_OUTPUTDIR . "/$obj->ref/$obj->ref.pdf";
if (file_exists($file)) if (file_exists($file))
{ {
print "<tr><td>Propale PDF</a></td>"; print "<tr $bc[0]><td>Propale PDF</a></td>";
print '<td><a href="'.PROPALE_OUTPUT_URL.'/'.$obj->ref.'/'.$obj->ref.'.pdf">'.$obj->ref.'.pdf</a></td></tr>'; print '<td><a href="'.PROPALE_OUTPUT_URL.'/'.$obj->ref.'/'.$obj->ref.'.pdf">'.$obj->ref.'.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></tr>';
} }
print "</table>\n"; print "</table>\n";
@ -389,20 +486,22 @@ if ($propalid) {
* *
*/ */
print "</td><td valign=\"top\" width=\"50%\">"; print "</td><td valign=\"top\" width=\"50%\">";
print "<b>Propale envoyée</b><br>"; print_titre("Propale envoyée");
/* /*
* *
*/ */
$sql = "SELECT ".$db->pdate("a.datea"). " as da, note, fk_user_author" ; $sql = "SELECT ".$db->pdate("a.datea"). " as da, note, fk_user_author" ;
$sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $obj->idp AND a.propalrowid = $propalid "; $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $obj->idp AND a.propalrowid = $propalid ";
if ( $db->query($sql) ) { if ( $db->query($sql) )
{
$num = $db->num_rows(); $num = $db->num_rows();
$i = 0; $total = 0; $i = 0; $total = 0;
print "<TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">"; print "<TABLE border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">";
print "<tr><td>Date</td><td>Auteur</td></TR>\n"; print "<tr><td>Date</td><td>Auteur</td></TR>\n";
while ($i < $num) { while ($i < $num)
{
$objp = $db->fetch_object( $i); $objp = $db->fetch_object( $i);
print "<TR><TD>".strftime("%d %B %Y %H:%M:%S",$objp->da)."</TD>\n"; print "<TR><TD>".strftime("%d %B %Y %H:%M:%S",$objp->da)."</TD>\n";
$authoract = new User($db); $authoract = new User($db);
@ -414,7 +513,9 @@ if ($propalid) {
} }
print "</table>"; print "</table>";
$db->free(); $db->free();
} else { }
else
{
print $db->error(); print $db->error();
} }
/* /*
@ -425,9 +526,8 @@ if ($propalid) {
* *
* *
*/ */
if ($action == 'presend') { if ($action == 'presend')
$sendto = "rq@lolix.org"; {
$replytoname = $conf->propal->replytoname; $replytoname = $conf->propal->replytoname;
$replytomail = $conf->propal->replytomail; $replytomail = $conf->propal->replytomail;
@ -435,11 +535,10 @@ if ($propalid) {
$from_mail = $user->email; //conf->propal->fromtomail; $from_mail = $user->email; //conf->propal->fromtomail;
print "<form method=\"post\" action=\"$PHP_SELF?propalid=$propalid&action=send\">\n"; print "<form method=\"post\" action=\"$PHP_SELF?propalid=$propalid&action=send\">\n";
print "<input type=\"hidden\" name=\"sendto\" value=\"$sendto\">\n";
print "<input type=\"hidden\" name=\"replytoname\" value=\"$replytoname\">\n"; print "<input type=\"hidden\" name=\"replytoname\" value=\"$replytoname\">\n";
print "<input type=\"hidden\" name=\"replytomail\" value=\"$replytomail\">\n"; print "<input type=\"hidden\" name=\"replytomail\" value=\"$replytomail\">\n";
print "<p><b>Envoyer la propale par mail</b>"; print_titre("Envoyer la propale par mail");
print "<table cellspacing=0 border=1 cellpadding=3>"; print "<table cellspacing=0 border=1 cellpadding=3>";
print "<tr><td>Destinataire</td><td colspan=\"5\">$obj->firstname $obj->name</td>"; print "<tr><td>Destinataire</td><td colspan=\"5\">$obj->firstname $obj->name</td>";
print "<td><input size=\"30\" name=\"sendto\" value=\"$obj->email\"></td></tr>"; print "<td><input size=\"30\" name=\"sendto\" value=\"$obj->email\"></td></tr>";
@ -452,7 +551,9 @@ if ($propalid) {
print "</form>"; print "</form>";
} }
} else { }
else
{
print "Num rows = " . $db->num_rows(); print "Num rows = " . $db->num_rows();
print "<p><b>$sql"; print "<p><b>$sql";
} }
@ -462,7 +563,8 @@ if ($propalid) {
* *
* *
*/ */
if ($suivi) { if ($suivi)
{
$validor = new User($db, $obj->fk_user_valid); $validor = new User($db, $obj->fk_user_valid);
$validor->fetch(''); $validor->fetch('');
$cloturor = new User($db, $obj->fk_user_cloture); $cloturor = new User($db, $obj->fk_user_cloture);
@ -480,11 +582,15 @@ if ($propalid) {
print '<tr><td>Cloture</td><td>'.$cloturor->fullname.'&nbsp;</td>'; print '<tr><td>Cloture</td><td>'.$cloturor->fullname.'&nbsp;</td>';
print '<td>'.$obj->date_cloture.'&nbsp;</td></tr>'; print '<td>'.$obj->date_cloture.'&nbsp;</td></tr>';
print '</table>'; print '</table>';
} else { }
else
{
print '<p><a href="'.$PHP_SELF.'?propalid='.$propal->id.'&suivi=1">Voir le suivi des actions </a>'; print '<p><a href="'.$PHP_SELF.'?propalid='.$propal->id.'&suivi=1">Voir le suivi des actions </a>';
} }
} else { }
else
{
print $db->error(); print $db->error();
print "<p><b>$sql"; print "<p><b>$sql";
} }