Fix: Can use POS module with several concurrent users. This also remove

temporary table.
This commit is contained in:
Laurent Destailleur 2011-10-13 20:14:29 +02:00
parent f5a593a291
commit f671df6634
7 changed files with 636 additions and 718 deletions

View File

@ -28,14 +28,14 @@ require_once('class/Facturation.class.php');
if ( $_GET['id'] == 'NOUV' ) if ( $_GET['id'] == 'NOUV' )
{ {
unset($_SESSION['serObjFacturation']); unset($_SESSION['serObjFacturation']);
$db->query('DELETE FROM '.MAIN_DB_PREFIX.'pos_tmp'); unset($_SESSION['poscart']);
} }
// Recuperation, s'il existe, de l'objet contenant les infos de la vente en cours ... // Recuperation, s'il existe, de l'objet contenant les infos de la vente en cours ...
if ( isset ($_SESSION['serObjFacturation']) ) if (isset($_SESSION['serObjFacturation']))
{ {
$obj_facturation = unserialize($_SESSION['serObjFacturation']); $obj_facturation = unserialize($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']); unset($_SESSION['serObjFacturation']);
} }
else else
{ {

File diff suppressed because it is too large Load Diff

View File

@ -31,87 +31,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<p class="titre"><?php echo $langs->trans("ShoppingCart"); ?></p> <p class="titre"><?php echo $langs->trans("ShoppingCart"); ?></p>
<?php <?php
// Recuperation du contenu de la vente /** add Ditto for MultiPrix*/
$request='SELECT id, ref, label, qte, price, remise_percent, remise, total_ht, total_ttc FROM '.MAIN_DB_PREFIX.'pos_tmp as c $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON c.fk_article = p.rowid $societe = new Societe($db);
ORDER BY id'; $societe->fetch($thirdpartyid);
dol_syslog($request); /** end add Ditto */
$res = $db->query($request);
if (! $res)
{
dol_print_error($db);
exit;
}
if ( $db->num_rows($res) ) $tab=array();
{ $tab = $_SESSION['poscart'];
$ret=array(); $i=0; $tab_size=count($tab);
if ($tab_size <= 0) print '<center>'.$langs->trans("NoArticle").'<center><br>';
else
{
for ($i=0;$i < $tab_size;$i++)
{
echo ('<div class="cadre_article">'."\n");
echo ('<p><a href="facturation_verif.php?action=suppr_article&suppr_id='.$tab[$i]['id'].'" title="'.$langs->trans("DeleteArticle").'">'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</a></p>'."\n");
/** add Ditto for MultiPrix*/ if ( $tab[$i]['remise_percent'] > 0 ) {
$thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
$societe = new Societe($db);
$societe->fetch($thirdpartyid);
/** end add Ditto */
while ( $tab = $db->fetch_array($res) ) $remise_percent = ' -'.$tab[$i]['remise_percent'].'%';
{
foreach ( $tab as $cle => $valeur )
{
$ret[$i][$cle] = $valeur;
}
/** add Ditto for MultiPrix*/ } else {
if($conf->global->PRODUIT_MULTIPRICES)
{
$product = new Product($db);
$product->fetch($ret[$i]['id']);
if(isset($product->multiprices[$societe->price_level])) $remise_percent = '';
{
$ret[$i]['price'] = $product->multiprices_ttc[$societe->price_level];
}
}
/** end add Ditto */
}
$i++; $remise = $tab[$i]['remise'];
}
$tab = $ret;
$tab_size=count($tab); echo ('<p>'.$tab[$i]['qte'].' x '.price2num($tab[$i]['price'], 'MT').$remise_percent.' = '.price2num($tab[$i]['total_ht'], 'MT').' '.$conf->monnaie.' '.$langs->trans("HT").' ('.price2num($tab[$i]['total_ttc'], 'MT').' '.$conf->monnaie.' '.$langs->trans("TTC").')</p>'."\n");
for($i=0;$i < $tab_size;$i++) { echo ('</div>'."\n");
}
}
echo ('<div class="cadre_article">'."\n"); $obj_facturation->calculTotaux();
echo ('<p><a href="facturation_verif.php?action=suppr_article&suppr_id='.$tab[$i]['id'].'" title="'.$langs->trans("DeleteArticle").'">'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</a></p>'."\n"); $total_ttc = $obj_facturation->prix_total_ttc();
echo ('<p class="cadre_prix_total">'.$langs->trans("Total").' : '.price2num($total_ttc, 'MT').' '.$conf->monnaie.'<br></p>'."\n");
if ( $tab[$i]['remise_percent'] > 0 ) { ?></div>
$remise_percent = ' -'.$tab[$i]['remise_percent'].'%';
} else {
$remise_percent = '';
}
$remise = $tab[$i]['remise'];
echo ('<p>'.$tab[$i]['qte'].' x '.price2num($tab[$i]['price'], 'MT').$remise_percent.' = '.price2num($tab[$i]['total_ht'], 'MT').' '.$conf->monnaie.' '.$langs->trans("HT").' ('.price2num($tab[$i]['total_ttc'], 'MT').' '.$conf->monnaie.' '.$langs->trans("TTC").')</p>'."\n");
echo ('</div>'."\n");
}
$obj_facturation->calculTotaux();
$total_ttc = $obj_facturation->prix_total_ttc();
echo ('<p class="cadre_prix_total">'.$langs->trans("Total").' : '.price2num($total_ttc, 'MT').' '.$conf->monnaie.'<br></p>'."\n");
} else {
echo ('<p class="cadre_aucun_article">'.$langs->trans("NoArticle").'</p>'."\n");
}
?>
</div>
</div> </div>

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net> /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,69 +30,63 @@ $object->fetch($facid);
<title>Print ticket</title> <title>Print ticket</title>
<style type="text/css"> <style type="text/css">
body {
font-size: 1.5em;
position: relative;
}
body { .entete { /* position: relative; */
font-size: 1.5em;
position: relative;
}
.entete { }
/* position: relative; */
}
.address { .address { /* float: left; */
/* float: left; */ font-size: 12px;
font-size: 12px; }
}
.date_heure { .date_heure {
position: absolute; position: absolute;
top: 0; top: 0;
right: 0; right: 0;
font-size: 16px; font-size: 16px;
} }
.infos { .infos {
position: relative; position: relative;
} }
.liste_articles {
width: 100%;
border-bottom: 1px solid #000;
text-align: center;
}
.liste_articles { .liste_articles tr.titres th {
width: 100%; border-bottom: 1px solid #000;
border-bottom: 1px solid #000; }
text-align: center;
}
.liste_articles tr.titres th { .liste_articles td.total {
border-bottom: 1px solid #000; text-align: right;
} }
.liste_articles td.total { .totaux {
text-align: right; margin-top: 20px;
} width: 30%;
float: right;
text-align: right;
}
.totaux { .lien {
margin-top: 20px; position: absolute;
width: 30%; top: 0;
float: right; left: 0;
text-align: right; display: none;
} }
@media print {
.lien { .lien {
position: absolute;
top: 0;
left: 0;
display: none; display: none;
} }
}
@media print {
.lien {
display: none;
}
}
</style> </style>
</head> </head>
@ -99,79 +94,61 @@ $object->fetch($facid);
<body> <body>
<div class="entete"> <div class="entete">
<div class="logo"> <div class="logo"><?php print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_small).'">'; ?>
<?php print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_small).'">'; ?> </div>
</div> <div class="infos">
<div class="infos"> <p class="address"><?php echo $mysoc->name; ?><br>
<p class="address"><?php echo $mysoc->name; ?><br> <?php print dol_nl2br(dol_format_address($langs,$mysoc)); ?><br>
<?php print dol_nl2br(dol_format_address($langs,$mysoc)); ?><br> </p>
</p>
<p class="date_heure"> <p class="date_heure"><?php
<?php // Recuperation et affichage de la date et de l'heure
// Recuperation et affichage de la date et de l'heure $now = dol_now();
$now = dol_now(); print dol_print_date($now,'dayhourtext').'<br>';
print dol_print_date($now,'dayhourtext').'<br>'; print $object->ref;
print $object->ref; ?></p>
?> </div>
</p>
</div>
</div> </div>
<br> <br>
<table class="liste_articles"> <table class="liste_articles">
<tr class="titres"><th><?php print $langs->trans("Code"); ?></th><th><?php print $langs->trans("Label"); ?></th><th><?php print $langs->trans("Qty"); ?></th><th><?php print $langs->trans("Discount").' (%)'; ?></th><th><?php print $langs->trans("TotalHT"); ?></th></tr> <tr class="titres">
<th><?php print $langs->trans("Code"); ?></th>
<th><?php print $langs->trans("Label"); ?></th>
<th><?php print $langs->trans("Qty"); ?></th>
<th><?php print $langs->trans("Discount").' (%)'; ?></th>
<th><?php print $langs->trans("TotalHT"); ?></th>
</tr>
<?php <?php
// Variables $tab=array();
$res = $db->query( $tab = $_SESSION['poscart'];
'SELECT id, ref, label, qte, price, remise_percent, remise, total_ht, total_ttc, tva_tx FROM '.MAIN_DB_PREFIX.'pos_tmp as c
LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON c.fk_article = p.rowid
ORDER BY id');
if ($db->num_rows($res)) $tab_size=count($tab);
{ for($i=0;$i < $tab_size;$i++)
$ret=array(); $i=0; {
while ($tab = $db->fetch_array($res)) $remise = $tab[$i]['remise'];
{ echo ('<tr><td>'.$tab[$i]['ref'].'</td><td>'.$tab[$i]['label'].'</td><td>'.$tab[$i]['qte'].'</td><td>'.$tab[$i]['remise_percent'].'</td><td class="total">'.price2num($tab[$i]['total_ht'],'MT').' '.$conf->monnaie.'</td></tr>'."\n");
foreach ($tab as $cle => $valeur) }
{
$ret[$i][$cle] = $valeur;
}
$i++;
}
$tab = $ret;
$tab_size=count($tab);
for($i=0;$i < $tab_size;$i++)
{
$remise = $tab[$i]['remise'];
echo ('<tr><td>'.$tab[$i]['ref'].'</td><td>'.$tab[$i]['label'].'</td><td>'.$tab[$i]['qte'].'</td><td>'.$tab[$i]['remise_percent'].'</td><td class="total">'.price2num($tab[$i]['total_ht'],'MT').' '.$conf->monnaie.'</td></tr>'."\n");
}
}
else
{
echo ('<p>Erreur : aucun article</p>'."\n");
}
?> ?>
</table> </table>
<table class="totaux"> <table class="totaux">
<?php <?php
echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalHT").'</th><td nowrap="nowrap">'.price2num($obj_facturation->prix_total_ht(),'MT')." ".$conf->monnaie."</td></tr>\n"; echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalHT").'</th><td nowrap="nowrap">'.price2num($obj_facturation->prix_total_ht(),'MT')." ".$conf->monnaie."</td></tr>\n";
echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalVAT").'</th><td nowrap="nowrap">'.price2num($obj_facturation->montant_tva(),'MT')." ".$conf->monnaie."</td></tr>\n"; echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalVAT").'</th><td nowrap="nowrap">'.price2num($obj_facturation->montant_tva(),'MT')." ".$conf->monnaie."</td></tr>\n";
echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalTTC").'</th><td nowrap="nowrap">'.price2num($obj_facturation->prix_total_ttc(),'MT')." ".$conf->monnaie."</td></tr>\n"; echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalTTC").'</th><td nowrap="nowrap">'.price2num($obj_facturation->prix_total_ttc(),'MT')." ".$conf->monnaie."</td></tr>\n";
?> ?>
</table> </table>
<script type="text/javascript"> <script type="text/javascript">
window.print(); window.print();
</script> </script>
<a class="lien" href="#" onclick="javascript: window.close(); return(false);"><?php echo $langs->trans("Close"); ?></a> <a class="lien" href="#"
onclick="javascript: window.close(); return(false);"><?php echo $langs->trans("Close"); ?></a>
</body> </body>

View File

@ -144,29 +144,15 @@ switch ($action)
$invoice=new Facture($db); $invoice=new Facture($db);
// Recuperation de la liste des articles du panier // Get content of cart
$res=$db->query('SELECT fk_article, qte, fk_tva, remise_percent, remise, total_ht, total_ttc $tab_liste = $_SESSION['poscart'];
FROM '.MAIN_DB_PREFIX.'pos_tmp
WHERE 1');
$ret=array(); $i=0;
while ($tab = $db->fetch_array($res))
{
foreach ($tab as $cle => $valeur)
{
$ret[$i][$cle] = $valeur;
}
$i++;
}
$tab_liste = $ret;
// Loop on each product // Loop on each product
$tab_liste_size=count($tab_liste); $tab_liste_size=count($tab_liste);
for($i=0;$i < $tab_liste_size;$i++) for ($i=0;$i < $tab_liste_size;$i++)
{ {
// Recuperation de l'article // Recuperation de l'article
$res = $db->query( $res = $db->query('SELECT label, tva_tx, price FROM '.MAIN_DB_PREFIX.'product WHERE rowid = '.$tab_liste[$i]['fk_article']);
'SELECT label, tva_tx, price
FROM '.MAIN_DB_PREFIX.'product
WHERE rowid = '.$tab_liste[$i]['fk_article']);
$ret=array(); $ret=array();
$tab = $db->fetch_array($res); $tab = $db->fetch_array($res);
foreach ( $tab as $cle => $valeur ) foreach ( $tab as $cle => $valeur )
@ -175,10 +161,7 @@ switch ($action)
} }
$tab_article = $ret; $tab_article = $ret;
$res = $db->query( $res = $db->query('SELECT taux FROM '.MAIN_DB_PREFIX.'c_tva WHERE rowid = '.$tab_liste[$i]['fk_tva']);
'SELECT taux
FROM '.MAIN_DB_PREFIX.'c_tva
WHERE rowid = '.$tab_liste[$i]['fk_tva']);
$ret=array(); $ret=array();
$tab = $db->fetch_array($res); $tab = $db->fetch_array($res);
foreach ( $tab as $cle => $valeur ) foreach ( $tab as $cle => $valeur )
@ -250,20 +233,6 @@ switch ($action)
$paiement_id = $payment->create($user); $paiement_id = $payment->create($user);
if ($paiement_id > 0) if ($paiement_id > 0)
{ {
/*if ( $obj_facturation->mode_reglement() == 'ESP' )
{
$bankaccountid=$conf_fkaccount_cash;
}
if ( $obj_facturation->mode_reglement() == 'CHQ' )
{
$bankaccountid=$conf_fkaccount_cheque;
}
if ( $obj_facturation->mode_reglement() == 'CB' )
{
$bankaccountid=$conf_fkaccount_cb;
}*/
if (! $error) if (! $error)
{ {
$result=$payment->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$bankaccountid,'',''); $result=$payment->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$bankaccountid,'','');

View File

@ -1,29 +0,0 @@
-- ===========================================================================
-- Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ===========================================================================
CREATE TABLE llx_pos_tmp (
id integer AUTO_INCREMENT PRIMARY KEY,
fk_article integer NOT NULL,
qte real NOT NULL,
fk_tva integer NOT NULL,
remise_percent real NOT NULL,
remise real NOT NULL,
total_ht double(24,8) NOT NULL,
total_tva double(24,8) NOT NULL,
total_ttc double(24,8) NOT NULL
) ENGINE=innodb;

View File

@ -8,8 +8,8 @@
// in [-]HH:MM format... // in [-]HH:MM format...
// won't yet work with non-even tzs // won't yet work with non-even tzs
function fetchTimezone() { function fetchTimezone()
// FIXME: work around Safari bug {
var localclock = new Date(); var localclock = new Date();
// returns negative offset from GMT in minutes // returns negative offset from GMT in minutes
var tzRaw = localclock.getTimezoneOffset(); var tzRaw = localclock.getTimezoneOffset();