Codice PHP:
<?php
<style type="text/css">
body {
background-color: ##f7b76b;
}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
table { max-width:500px;padding:0px;margin:0px;}
.cen{text-align:center;}
.cenRO{text-align:center; background-color: #FF0000;}
.cenS{background-color: #CCCCCC; font-size:12px; text-align:center;}
.cenD{background-color: #FF0000; font-size:12px; text-align:center;}
.dx{text-align:right;}
.sx{text-align:left;}
INPUT { color: #000080; /* colore testo */
background-color: transparent; /* sfondo trasparente */
font-family: GENEVA;
font-size: 12px;
border-style: solid; border-width: 0; /* senza bordi */
}
</style>
<script type="text/javascript">
function check_form() {
return confirm("sicuro di aver finito?");
}
</script>
</head>
<body>
<?php
require_once "connect.php";
if(isset($_POST['azzera'])){
if(isset($_SESSION)){
$op=$_SESSION['user'];
//$bc=$_SESSION['barcode'];//?? è quello che inserisco nell'input?
if(isset($_SESSION)){session_destroy();}
$_SESSION['user']=$op;
}
if(isset($_POST)){unset($_POST);}
echo "<meta http-equiv='Refresh' content='0; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
}
if(isset($_POST['calcola'])){
$_SESSION['contanti']=number_format($_POST['contanti'],2,'.', '');
$_SESSION['flag']="calcolo";
$bar_c=array();
$bar_c=$_POST['codice'];
$_SESSION['totale']=0;
for($j=0; $j < count($bar_c); $j++){
$kiave=trim($bar_c[$j]);
if($kiave !=""){
$pre="prezzo".$kiave.$j;
$_SESSION[$pre]=number_format($_POST['prezzo'][$j],2,'.', '');
$ds="Descrizione".$kiave.$j;
$_SESSION[$ds]=$_POST['descrizione'][$j];
//var_dump($_POST['elimina']); echo "<br>";
$q="qnt".$kiave.$j;
if($_POST['elimina'][$j]==$kiave){
$_SESSION[$q]=0;
}else{
$_SESSION[$q]=number_format($_POST['qnt'][$j],1,'.', '');
}
$sc="sconto".$kiave.$j;
$_SESSION[$sc]=number_format($_POST['sconto'][$j],1,'.', '');
$sc_v="scontov".$kiave.$j;
$_SESSION[$sc_v]=number_format($_POST['scontov'][$j],2,'.', '');
$tot="tot_code".$kiave.$j;
if($_SESSION[$sc]==0 && $_SESSION[$sc_v]==0){
$_SESSION[$tot]=number_format($_SESSION[$pre]*$_SESSION[$q],2,'.', '');
}elseif($_SESSION[$sc]==0 && $_SESSION[$sc_v]!=0){
$_SESSION[$tot]=number_format($_SESSION[$pre]*$_SESSION[$q]-$_SESSION[$sc_v],2,'.', '');
$_SESSION[$sc]=number_format($_SESSION[$sc_v]/($_SESSION[$pre]*$_SESSION[$q])*100,1,'.', '');
}else{
$_SESSION[$tot]=number_format($_SESSION[$pre]*(1-$_SESSION[$sc]/100)*$_SESSION[$q],2,'.', '');
$_SESSION[$sc_v]=number_format(($_SESSION[$pre]*$_SESSION[$q])-$_SESSION[$tot],2,'.', '');
}
$_SESSION['totale'] +=number_format($_SESSION[$tot],2,'.', '');
if($_POST['salva'][$j]==$kiave && $_POST['elimina'][$j]== NULL){
$q_c=mysql_query("SELECT Barcode FROM articoli WHERE Barcode='$kiave'");
if(mysql_num_rows($q_c) ==0){
if($_SESSION[$ds]=="" || $_SESSION[$pre] ==""){
echo "dati incompleti per barcode $kiave<br>";
}else{
$q_i="INSERT INTO articoli(Fornitore, Descrizione, Barcode, Vendita) VALUES('pallino','{$_SESSION[$ds]}','$kiave','{$_SESSION[$pre]}')";
$ris=mysql_query($q_i);
}
}
}
}
}
}
if(isset($_POST['barcodeart_new']) || $_SESSION['flag']=="calcolo" || $_SESSION['torno']=="ok"){
if(isset($_SESSION['flag'])){unset($_SESSION['flag']);$_SESSION['flag']="finito"; }//**
$_SESSION['barcode'][]=$_POST['barcodeart_new'];
?>
<form name="righe" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table border="0" cellspacing="0" width="500">
<tr>
<th class="sx" width="13">barcode</th>
<th class="sx" width="25">descrizione</th>
<th class="dx" width="5">prezzo €</th>
<th class="cen" width="3">quantità</th>
<th class="dx" width="4">sconto %</th>
<th class="dx" width="5">sconto valore €</th>
<th class="dx" width="7">importo €</th>
<th class="cenS" width="7">salva</th>
<th class="cenD" width="7">del.riga</th>
</tr>
<?php
$conta=0;
foreach($_SESSION['barcode'] as $ch => $val){
if($val!=""){
$query=mysql_query("SELECT * FROM articoli WHERE Barcode='$val'");
if(mysql_num_rows($query)==0){
$lettura="";
$salva="<td class=\"cenS\"><input type=\"checkbox\" name=\"salva[$conta]\" value=\"$val\"></td>";
}else{
$lettura="readonly";
$salva="<td class=\"cenS\"> </td>";
}
$riga=mysql_fetch_array($query);
echo "<tr>";
//****codice
echo "<td width=\"13\"><input name=\"codice[$conta]\" type=\"text\" id=\"codice\" value=\"$val\" readonly=\"true\"></td>";
//****descrixione
$ds1="Descrizione".$val.$conta;
if(isset($_SESSION[$ds1])){$descizione=$_SESSION[$ds1];}else{$descizione=$riga['Descrizione'];}
echo "<td width=\"25\"><input name=\"descrizione[$conta]\" type=\"text\" id=\"descrizione\" value=\"$descizione\"></td>";
//****prezzo
$p1="prezzo".$val.$conta;
if(isset($_SESSION[$p1])){$prezzo=$_SESSION[$p1];}else{$prezzo=$riga['Vendita'];}
echo "<td align=\"right\" width=\"7\"><input name=\"prezzo[$conta]\" type=\"text\" id=\"prezzo\" size=\"10\" value=\"$prezzo\" $lettura class=\"dx\"></td>";
//****quantità
$q1="qnt".$val.$conta;
if(isset($_SESSION[$q1])){$qnt=$_SESSION[$q1];}else{$qnt=1;}
$stile="cen";
if($qnt==0){$stile="cenRO";}
echo "<td class=\"cen\" width=\"3\"><input name=\"qnt[$conta]\" type=\"text\" id=\"qnt\" size=\"5\" value=\"$qnt\" class=\"$stile\"></td>";
//****csconto per cento
$sc1="sconto".$val.$conta;
if(isset($_SESSION[$sc1])){$sconto=$_SESSION[$sc1];}else{$sconto=0;}
echo "<td align=\"right\" width=\"5\"><input name=\"sconto[$conta]\" type=\"text\" id=\"sconto\" value=\"$sconto\" class=\"dx\" size=\"4\"></td>";
//****sconto valore
$scv="scontov".$val.$conta;
if(isset($_SESSION[$scv])){$scontov=$_SESSION[$scv];}else{$scontov=0;}
echo "<td align=\"right\" width=\"7\"><input name=\"scontov[$conta]\" type=\"text\" id=\"sctov\" value=\"$scontov\" class=\"dx\" size=\"10\"></td>";
//****totale riga
$tc1="tot_code".$val.$conta;
if(isset($_SESSION[$tc1])){$tot_code=$_SESSION[$tc1];}else{$tot_code="";}
echo"<td align=\"right\" width=\"7\"><input name=\"tot_code[$conta]\" type=\"text\" id=\"tot_code\" value=\"$tot_code\" readonly=\"true\" class=\"dx\"size=\"14\"></td>";
echo $salva;
echo "<td class=\"cenD\"><input type=\"checkbox\" name=\"elimina[$conta]\" value=\"$val\"></td>";
echo "</tr>";
$conta++;
}
}
?>
<tr>
<td width="13"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td class="dx"><strong>TOTALE</strong></td>
<td class="dx"><strong>
<?php
//****** totale generale
if(isset($_SESSION['totale'])){
echo number_format($_SESSION['totale'],2,'.', '');
}else{
echo "0.00";
}
?>
</strong></td>
<td>€</td>
<td> </td>
</tr>
<tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td class="dx"><strong>CONTANTI</strong></td>
<td class="dx"><strong>
<?php
//*****pagamento
if(isset($_SESSION['contanti'])){
$paga=number_format($_SESSION['contanti'],2,'.', '');
}else{
$paga=0.00;$_SESSION['contanti']=0.00;
}
echo "<input name=\"contanti\" type=\"text\" id=\"contanti\" value=\"$paga\" class=\"dx\">";
?>
</strong></td>
<td>€</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td class="dx"><strong>RESTO</strong></td>
<td class="dx"><strong>
<?php
//****resto
if(isset($_SESSION['totale']) && isset($_SESSION['contanti'])){
$resto= number_format($_SESSION['contanti']-$_SESSION['totale'],2);
}elseif(isset($_SESSION['totale']) && !isset($_SESSION['contanti'])){
$resto= number_format(-$_SESSION['totale'],2,'.', '');
}else{
$resto=0;
}
$colore="#000000";
if($resto<0){$colore="#FF0000";}
echo "<span style=\"color:$colore \">$resto</span>";
?>
</strong></td>
<td>€</td>
<td> </td>
</tr>
<tr>
<tr>
<td> </td>
<td><input name="azzera" type="submit" id="azzera" value="azzera"></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input name="calcola" type="submit" id="calcola" value="calcola"></td>
</tr>
</tr>
</table>
</form>
<?php
if($_SESSION['flag']=="finito"){
?>
<br />
<?php
}
}else{
?>
<?php
}
?>
</body>
</html>