233 lines
7.5 KiB
Perl
Executable File
233 lines
7.5 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
#script cgi de la page de commande
|
|
|
|
use DBI;
|
|
use CGI;
|
|
|
|
require "cgi-lib.pl";
|
|
|
|
$taux_tva = 0.196;
|
|
|
|
# recuperer toutes les donnees necessaires a la mise a jour du panier
|
|
&ReadParse(*query);
|
|
|
|
$ID_client_el = $query{'ID_client_el'};
|
|
|
|
$suppr1 = $query{'suppr-1'};
|
|
$suppr2 = $query{'suppr-2'};
|
|
$suppr3 = $query{'suppr-3'};
|
|
|
|
$famille1 = $query{'code_famille1'};
|
|
$famille2 = $query{'code_famille2'};
|
|
$famille3 = $query{'code_famille3'};
|
|
|
|
$produit1 = $query{'code_produit1'};
|
|
$produit2 = $query{'code_produit2'};
|
|
$produit3 = $query{'code_produit3'};
|
|
|
|
$qte1 = $query{'qte1'};
|
|
$qte2 = $query{'qte2'};
|
|
$qte3 = $query{'qte3'};
|
|
|
|
$html = new CGI;
|
|
|
|
print $html->header;
|
|
|
|
print "<HTML>\n";
|
|
print "<HEAD>\n";
|
|
print "<TITLE>Votre sélection</TITLE>\n";
|
|
print "</HEAD>\n";
|
|
print "<BODY BGCOLOR=\"\#FFFFFF\">\n";
|
|
print "<BODY BGCOLOR=\"\#FFFFFF\">\n";
|
|
print "<spacer TYPE=\"block\" HEIGHT=12>\n";
|
|
print "<CENTER><H1>Votre sélection</H1></CENTER>\n";
|
|
print "<HR SIZE=7 NO SHADE>\n";
|
|
print "<P>\n";
|
|
|
|
print "<CENTER>";
|
|
|
|
# affichage du debut du calepin
|
|
print "<FORM METHOD=\"post\" ACTION=\"http://o2000/cgi/recalc_com.pl\">\n";
|
|
print "<TABLE BORDER=0 CELLSPACING=5 CELLPADING=3>\n";
|
|
print "<TR BGCOLOR=\"\#FFFFCC\" NOSAVE>\n";
|
|
print "<TD ></TD>\n";
|
|
print "<TD ><!- colonne reservee au numero du produit (compte) -></TD>\n";
|
|
print "<TD ><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>Ref</FONT></TD>\n";
|
|
print "<TD ><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>Désignation</FONT></TD>\n";
|
|
print "<TD ><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>Qté</FONT></TD>\n";
|
|
print "<TD ><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>Prix unitaire HT </FONT></TD>\n";
|
|
print "<TD ><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>Sous-total HT</FONT></TD>\n";
|
|
print "</TR>\n";
|
|
|
|
# se connecter a la base
|
|
$dbh = DBI->connect("dbi:Pg:dbname=s_marchand", postgres, ) or die $DBI::errstr;
|
|
|
|
# supprimer les articles decoches
|
|
if ($suppr1 eq "on"){
|
|
&maj_panier($ID_client_el, $famille1, $produit1, $qte1);
|
|
}else{
|
|
&supprimer ($ID_client_el, $famille1, $produit1);
|
|
}
|
|
|
|
if ($suppr2 eq "on"){
|
|
&maj_panier($ID_client_el, $famille2, $produit2, $qte2);
|
|
}else{
|
|
&supprimer ($ID_client_el, $famille2, $produit2);
|
|
}
|
|
|
|
if ($suppr3 eq "on"){
|
|
&maj_panier($ID_client_el, $famille3, $produit3, $qte3);
|
|
}else{
|
|
&supprimer ($ID_client_el, $famille3, $produit3);
|
|
}
|
|
|
|
&afficher_calepin();
|
|
|
|
# se deconnecter de la base
|
|
$dbh->disconnect;
|
|
|
|
#afficher la fin de la page de selection des produits
|
|
print "<P><P>\n";
|
|
|
|
# boutons de gestion de la commande
|
|
print "<TABLE BORDER=1 CELLSPACING=0 CELLPADING=1>\n";
|
|
print "<TR>\n";
|
|
print "<TD ></TD>\n";
|
|
print "<TD ></TD>\n";
|
|
print "<FORM METHOD=\"post\" ACTION=\"http://o2000/cgi/commander.pl\" >\n";
|
|
print "<TD><INPUT TYPE=\"Submit\" VALUE=\"Commander\"></TD>\n";
|
|
print "<INPUT TYPE=\"hidden\" NAME=\"ID_client_el\" VALUE=$ID_client_el>\n";
|
|
print "</FORM>\n";
|
|
print "<TD ></TD>\n";
|
|
print "<TD ></TD>\n";
|
|
print "<FORM METHOD=\"post\" ACTION=\"http://o2000/cgi/bdd_prod.pl\" >\n";
|
|
print "<TD><INPUT TYPE=submit VALUE='Voir les produits' NAME='go' bgclor=\"\#99CCFF\"></TD>\n";
|
|
print "</FORM>\n";
|
|
print "</TR>\n";
|
|
print "</TABLE>\n";
|
|
print "<P><P>\n";
|
|
|
|
print "</CENTER>";
|
|
|
|
print "Pour <B>ajouter des articles</B>, retournez sur le catalogue et sélectionnez les articles choisis.<BR>\n";
|
|
print "Pour <B>supprimer un article</B> de votre sélection, vous devez le décocher, puis cliquer sur le bouton recalculer pour mettre à jour les totaux.<BR>\n";
|
|
print "Pour <B>commander plusieurs exemplaires</B> d\'un produit, modifiez sa quantité puis recalculez le montant de votre commande.<BR>\n";
|
|
print "Lorsque vous êtes <B>satisfait de votre sélection</B>, cliquez sur le bouton <B>commander</B>.\n";
|
|
|
|
print "<\BODY>";
|
|
print "<\HTML>\n";
|
|
|
|
sub maj_panier {
|
|
|
|
$arg1 = $_[0];
|
|
$arg2 = $_[1];
|
|
$arg3 = $_[2];
|
|
$qte = $_[3];
|
|
|
|
$maj_panier = $dbh->prepare( "UPDATE panier SET qte = $qte" .
|
|
"WHERE id_client_el='$arg1' " .
|
|
"AND code_famille='$arg2' " .
|
|
"AND code_produit='$arg3'");
|
|
|
|
$maj_panier->execute;
|
|
$maj_panier->finish;
|
|
}
|
|
|
|
|
|
sub supprimer {
|
|
|
|
$arg1 = $_[0];
|
|
$arg2 = $_[1];
|
|
$arg3 = $_[2];
|
|
|
|
$cursor = $dbh->prepare("DELETE FROM panier " .
|
|
"WHERE id_client_el='$arg1' " .
|
|
"AND code_famille='$arg2' " .
|
|
"AND code_produit='$arg3'");
|
|
$cursor->execute;
|
|
$cursor->finish;
|
|
}
|
|
|
|
sub afficher_calepin {
|
|
# recuperer les produits selectionnes par le client concerne
|
|
$cursor = $dbh->prepare( "SELECT pa.code_famille, pa.code_produit, pr.denomination, pa.qte, pr.prix_ht " .
|
|
"FROM produits pr, panier pa " .
|
|
"WHERE pa.id_client_el like '$ID_client_el' " .
|
|
"AND pa.code_famille = pr.code_famille " .
|
|
"AND pa.code_produit= pr.code_produit" );
|
|
$cursor->execute;
|
|
|
|
$cpt = 1;
|
|
|
|
while ( @lgcom = $cursor->fetchrow) {
|
|
($code_famille,$code_produit,$denomination,$qte,$prix_ht) = @lgcom;
|
|
|
|
print "<TR BGCOLOR=\"\#99CCFF\" NOSAVE>\n";
|
|
print "<TD><INPUT TYPE=\"checkbox\" NAME=\"suppr-$cpt\" SIZE=2 CHECKED></TD>\n";
|
|
print "<TD><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$cpt<!-numero de ligne></TD>\n";
|
|
print "<TD><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$code_famille $code_produit<!-reference produit></TD>\n";
|
|
print "<TD><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$denomination<!-nom produit></TD>\n";
|
|
print "<TD><INPUT TYPE=\"text\" NAME=\"qte$cpt\" SIZE=2 VALUE=$qte ></TD>\n";
|
|
print "<TD ALIGN=\"right\"><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$prix_ht<!-prix unitaire hors taxe></TD>\n";
|
|
|
|
$s_total = $prix_ht * $qte;
|
|
|
|
print "<TD ALIGN=\"right\"><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$s_total</FONT></TD>\n";
|
|
print "<INPUT TYPE=\"hidden\" NAME=\"code_famille$cpt\" VALUE=\"$code_famille\">\n";
|
|
print "<INPUT TYPE=\"hidden\" NAME=\"code_produit$cpt\" VALUE=\"$code_produit\">\n";
|
|
#print "<INPUT TYPE=\"hidden\" NAME=\"nb_lignes\" VALUE=\"$cpt\">\n";
|
|
print "</TR>\n";
|
|
$total_ht += $s_total;
|
|
|
|
$cpt++;
|
|
}
|
|
|
|
$cursor->finish;
|
|
|
|
|
|
print "<INPUT TYPE=\"hidden\" NAME=\"nb_lignes\" VALUE=$cpt>\n";
|
|
|
|
# calcul de la tva
|
|
$tva = $total_ht * $taux_tva;
|
|
|
|
# calcul du total hors taxe
|
|
$total_ttc = $total_ht + $tva ;
|
|
|
|
# affichage des totaux
|
|
print "<TR BGCOLOR=\"\#FFFFCC\" NOSAVE>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD ALIGN=\"right\"><FONT SIZE=4><B><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5><HR><BR>Total H\.T\. \: </B></FONT></TD>\n";
|
|
print "<TD ALIGN=\"right\"><FONT SIZE=4><B><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5><hr><BR>$total_ht</B></FONT></TD>\n";
|
|
print "</TR>\n";
|
|
print "<TR BGCOLOR=\"\#99CCFF\" NOSAVE>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD ALIGN=\"right\"><FONT SIZE=4><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>T\.V\.A\.\ (19,6 \%\) \: </FONT></TD>\n";
|
|
print "<TD ALIGN=\"right\"><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$tva</TD>\n";
|
|
print "</TR>\n";
|
|
print "<TR BGCOLOR=\"#FFFFCC\" NOSAVE>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD></TD>\n";
|
|
print "<TD ALIGN=\"right\"><FONT SIZE=4><B><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>TOTAL T\.\T.\C\. \: </FONT></B></TD>\n";
|
|
print "<TD ALIGN=\"right\"><FONT SIZE=4><B><spacer TYPE=\"block\" WIDTH=5 HEIGHT=5>$total_ttc</FONT></B></TD>\n";
|
|
print "</TR>\n";
|
|
print "<TR>\n";
|
|
print "<TD COLSPAN=7 ALIGN=right><INPUT TYPE=\"submit\" VALUE=\"Recalculer\" ></TD>\n";
|
|
print "</TR>\n";
|
|
print "</TABLE>\n";
|
|
print "<INPUT TYPE=\"hidden\" NAME=\"ID_client_el\" VALUE=\"$ID_client_el\" >\n";
|
|
|
|
print "</FORM>\n";
|
|
}
|