Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    scarico merce con lettore di codici a barre

    salve, sto realizzando un progetto che prevede lo scaricamento di prodotti da magazzino per mezzo di un lettore di codici a barre.

    Se il codice prodotto inserito corrisponde a quello di un prodotto presente in database, questo viene visualizzato cn una serie di dettagli (prezzo, qtà, descrizione...), la quantità nel db diminuisce di una unità e il costo viene aggiunto al totale pagamento lato client.

    evito altri dettagli e vado al sodo: devo implementare tre funzionalità essenziali che mi stanno facendo impazzire.

    1. calcolo del totale
    2. aggiungi unità al database onclick sul tasto elimina
    3. alert se viene inserito un codice errato o vuoto

    forse sarebbe meglio affrontare un problema alla volta, ma ho molta urgenza di portare a termine il lavoro e dato che ormai sono giorni che provo a risolvere senza risultato sarei moooolto grato se qualcuno provasse a darmi una mano...

    grazie in anticipo




    file index.php:
    codice:
    <?php
    session_start();
    $products = null;
    
    if (!empty($_SESSION['products'])) {
    	$products = $_SESSION['products'];
    }
    ?>
    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    	<meta charset="utf-8">
    	<title>BarCode</title>
    	<meta name="description" content="">
    	<meta name="keywords" content="">
    	<meta http-equiv="imagetoolbar" content="no" />
    	<link href="css/core.css" rel="stylesheet" type="text/css" />
    	<!--[if lt IE 9]>
    	<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    	<![endif]-->
    </head>
    <body>
    
    <div id="wrapper">
    	<form action="" method="post" id="form_products">
    		<input type="text" id="name" name="name"
    			class="field field_medium"
    			placeholder="Codice Prodotto" value="" />
    			Cerca
    			Conferma e Paga
    
    </form>
    	<div id="table_wrapper">
    		
    
    Inserisci un codice prodotto per iniziare la transazione.</p>
    	</div>
    </div>
    <script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="js/core.js" type="text/javascript"></script>
    </body>
    </html>

    file core.js:
    codice:
     
    $(document).ready(function() {
    
    
    	
    	$('.remove').live('click', function() {
    		
    		var trigger = $(this);
    		var id = $(this).attr('rel');
    		
    		$.getJSON('mod/remove.php?id='+id, function(data) {
    			
    			var rows = $('.tbl_repeat tr').length;
    			if (rows > 2) {
    				trigger.closest('tr').fadeOut(300, function() {
    					$(this).remove();
    				});
    			} else {
    				$('.tbl_repeat').fadeOut(300, function() {
    					var msg = '
    
    Inserisci un codice prodotto per iniziare la transazione.</p>';
    					$('#table_wrapper').hide().html(msg).fadeIn(300);
    				});
    			}
    			
    		});
    		
    		return false;
    		
    	});
    	
    
    
    	$('#name').keypress(function(event){
    		
    	var keycode = (event.keyCode ? event.keyCode : event.which);
    	if(keycode == '13'){
    		var arr = $(this).closest('form').serializeArray();
    		var tbl = $('.tbl_repeat').length;
    		$.post('mod/row.php?tbl='+tbl, arr, function(data) {
    			if (tbl === 0) {
    				$('#table_wrapper').html(
    					$(data.row).hide().fadeIn(300)
    				);
    			} else {
    				$('.tbl_repeat tr:last').after(
    					$(data.row).hide().fadeIn(300)
    						.css('display', 'table-row')
    				);
    			}
    		}, 'json');
    		$("#name").val("");
    		return false;		
    	}
    	event.stopPropagation();
    	});
     	
    	
    	$('.add_new').click(function() {	
    	
    		var arr = $(this).closest('form').serializeArray();
    		var tbl = $('.tbl_repeat').length;
    		$.post('mod/row.php?tbl='+tbl, arr, function(data) {
    			if (tbl === 0) {
    				$('#table_wrapper').html(
    					$(data.row).hide().fadeIn(300)
    				);
    			} else {
    				$('.tbl_repeat tr:last').after(
    					$(data.row).hide().fadeIn(300)
    						.css('display', 'table-row')
    				);
    			}
    		}, 'json');
    		$("#name").val("");
    		return false;		
    	});
    
    });

    file row.php:
    codice:
     
    ?php
    
    session_start();
    
    $link = mysql_connect('XXX', 'XXX', 'XXX') or die('Impossibile connettersi al database');
    	mysql_select_db('XXX') or die('Impossibile selezionare il database');
    
    	if(isset($_POST['name']) and $_POST['name'] != "" )  {		
    			$q = mysql_query("UPDATE ecorient_product SET quantity = quantity - 1 WHERE ean = '" . $_POST['name'] . "'") or die ("ERRORE! Impossibile aggiornare la disponibilità di magazzino per il prodotto: " . $_POST['name']);
    			
    	} 	
    	else {
    		 exit;
    		 }
    
    	$rs = mysql_query("SELECT * FROM ecorient_product, ecorient_product_description WHERE ean = '" . $_POST['name'] . "' AND ecorient_product_description.product_id = ecorient_product.product_id") or die ('Impossibile elaborare numero di query SQL totali');
    	
    	if(mysql_num_rows($rs) > 0) {
    		while($row = mysql_fetch_array($rs)) {
    			$name_[$row['ean']] = $row['name'];
    			$count[$row['ean']] = $row['quantity'];
    			$price[$row['ean']] = $row['price'];
    		}	
    	} 
    	else {
    		 exit;
    		 }
    
    $tbl = !empty($_GET['tbl']) ? $_GET['tbl'] : 0;
    $name = !empty($_POST['name']) ? $_POST['name'] : '';
    
    //$index = !empty($_SESSION['products']) ? count($_SESSION['products']) + 1 : 1;
    
    $index = 0;
    if (!empty($_SESSION['products'])) {
        foreach($products as $key => $row) {
            $index = $key;
        }
    }
    $index = $index + 1;
    
    $_SESSION['products'][$index] = array(
    	'name' => $name
    );
    
    $row  = '<tr>';
    $row .= '<td>'.$name_[$_POST['name']].'</td>';
    $row .= '<td class="ta_r">'.$name.'</td>';
    $row .= '<td class="ta_r">'.sprintf("%.2f",$row['price']).' &euro;</td>';
    $row .= '<td class="ta_r">'.$count[$_POST['name']].'</td>';
    $row .= '<td class="ta_r">Elimina</td>';
    $row .= '</tr>';
    
    if (empty($tbl)) {
    	$out  = '<table cellpadding="0" cellspacing="0" ';
    	$out .= 'border="0" class="tbl_repeat">';
    	$out .= '<tr>';
    	$out .= '<th>Nome Prodotto</th>';
    	$out .= '<th class="col_1 ta_r">Codice</th>';
    	$out .= '<th class="col_1 ta_r">Prezzo</th>';
    	$out .= '<th class="col_1 ta_r">Qt&agrave</th>';
    	$out .= '<th class="col_1 ta_r"></th>';
    	$out .= '</tr>';
    	$out .= $row;
    	$out .= '</table>';
    	$out .= '<table cellpadding="0" cellspacing="0" border="0" class="tbl_repeat2"><tr><th>TOTALE:</th></tr></table>';
    
    	$row = $out;
    
    }
    echo json_encode(array('row' => $row));

  2. #2
    adesso non ho tempo di farti il codice, però ti do un consiglio veloce.. per il primo problema puoi risolvere così..
    1. prendi l'ID del record di quel prodotto e la quantità dal database
    2. quantità = quantità - 1
    3. usando l'id fai un UPDATE e cambi il valore quantità con quello nuovo..

    per il secondo problema fai una cosa uguale ma con il + 1 (non so dirti come fare con onclick perché non l'ho mai usato, domani vado a studiarmelo)

    per il terzo problema esegui una query con WHERE codice = codice_scannerizzato.. poi conti le righe con mysql_num_rows e se è uguale a 0 vuol dire che il codice è sbagliato e fai scrivere con echo quello che vuoi (anche popup in javascript credo si possano aprire con echo)

    spero di essere stato abbastanza chiaro, domani provo a dargli un'occhiata e vedo se riesco a aggiungere quello che ho detto al tuo codice.. intanto provaci tu e fammi sapere a che punto arrivi

  3. #3
    Grazie, ho risolto....anche se mi è costato parecchie nottate.
    Se a qualcuno interessa il codice sistemato per ii propri impieghi non ha che da chiedere.
    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.