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' )
{
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 ...
if ( isset ($_SESSION['serObjFacturation']) )
if (isset($_SESSION['serObjFacturation']))
{
$obj_facturation = unserialize($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']);
unset($_SESSION['serObjFacturation']);
}
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>
<?php
// Recuperation du contenu de la vente
$request='SELECT id, ref, label, qte, price, remise_percent, remise, total_ht, total_ttc 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';
dol_syslog($request);
$res = $db->query($request);
if (! $res)
{
dol_print_error($db);
exit;
}
/** add Ditto for MultiPrix*/
$thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
$societe = new Societe($db);
$societe->fetch($thirdpartyid);
/** end add Ditto */
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*/
$thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
$societe = new Societe($db);
$societe->fetch($thirdpartyid);
/** end add Ditto */
if ( $tab[$i]['remise_percent'] > 0 ) {
while ( $tab = $db->fetch_array($res) )
{
foreach ( $tab as $cle => $valeur )
{
$ret[$i][$cle] = $valeur;
}
$remise_percent = ' -'.$tab[$i]['remise_percent'].'%';
/** add Ditto for MultiPrix*/
if($conf->global->PRODUIT_MULTIPRICES)
{
$product = new Product($db);
$product->fetch($ret[$i]['id']);
} else {
if(isset($product->multiprices[$societe->price_level]))
{
$ret[$i]['price'] = $product->multiprices_ttc[$societe->price_level];
}
}
/** end add Ditto */
$remise_percent = '';
}
$i++;
}
$tab = $ret;
$remise = $tab[$i]['remise'];
$tab_size=count($tab);
for($i=0;$i < $tab_size;$i++) {
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");
}
}
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");
$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");
if ( $tab[$i]['remise_percent'] > 0 ) {
$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
/* 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
* it under the terms of the GNU General Public License as published by
@ -29,69 +30,63 @@ $object->fetch($facid);
<title>Print ticket</title>
<style type="text/css">
body {
font-size: 1.5em;
position: relative;
}
body {
font-size: 1.5em;
position: relative;
}
.entete { /* position: relative; */
.entete {
/* position: relative; */
}
}
.address {
/* float: left; */
font-size: 12px;
}
.address { /* float: left; */
font-size: 12px;
}
.date_heure {
position: absolute;
top: 0;
right: 0;
font-size: 16px;
}
.date_heure {
position: absolute;
top: 0;
right: 0;
font-size: 16px;
}
.infos {
position: relative;
}
.infos {
position: relative;
}
.liste_articles {
width: 100%;
border-bottom: 1px solid #000;
text-align: center;
}
.liste_articles {
width: 100%;
border-bottom: 1px solid #000;
text-align: center;
}
.liste_articles tr.titres th {
border-bottom: 1px solid #000;
}
.liste_articles tr.titres th {
border-bottom: 1px solid #000;
}
.liste_articles td.total {
text-align: right;
}
.liste_articles td.total {
text-align: right;
}
.totaux {
margin-top: 20px;
width: 30%;
float: right;
text-align: right;
}
.totaux {
margin-top: 20px;
width: 30%;
float: right;
text-align: right;
}
.lien {
position: absolute;
top: 0;
left: 0;
display: none;
}
@media print {
.lien {
position: absolute;
top: 0;
left: 0;
display: none;
}
@media print {
.lien {
display: none;
}
}
}
</style>
</head>
@ -99,79 +94,61 @@ $object->fetch($facid);
<body>
<div class="entete">
<div class="logo">
<?php print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_small).'">'; ?>
</div>
<div class="infos">
<p class="address"><?php echo $mysoc->name; ?><br>
<?php print dol_nl2br(dol_format_address($langs,$mysoc)); ?><br>
</p>
<div class="logo"><?php print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_small).'">'; ?>
</div>
<div class="infos">
<p class="address"><?php echo $mysoc->name; ?><br>
<?php print dol_nl2br(dol_format_address($langs,$mysoc)); ?><br>
</p>
<p class="date_heure">
<?php
// Recuperation et affichage de la date et de l'heure
$now = dol_now();
print dol_print_date($now,'dayhourtext').'<br>';
print $object->ref;
?>
</p>
</div>
<p class="date_heure"><?php
// Recuperation et affichage de la date et de l'heure
$now = dol_now();
print dol_print_date($now,'dayhourtext').'<br>';
print $object->ref;
?></p>
</div>
</div>
<br>
<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
// Variables
$res = $db->query(
'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');
$tab=array();
$tab = $_SESSION['poscart'];
if ($db->num_rows($res))
{
$ret=array(); $i=0;
while ($tab = $db->fetch_array($res))
{
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");
}
$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");
}
?>
</table>
<table class="totaux">
<?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("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";
?>
<?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("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";
?>
</table>
<script type="text/javascript">
window.print();
</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);
// Recuperation de la liste des articles du panier
$res=$db->query('SELECT fk_article, qte, fk_tva, remise_percent, remise, total_ht, total_ttc
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;
// Get content of cart
$tab_liste = $_SESSION['poscart'];
// Loop on each product
$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
$res = $db->query(
'SELECT label, tva_tx, price
FROM '.MAIN_DB_PREFIX.'product
WHERE rowid = '.$tab_liste[$i]['fk_article']);
$res = $db->query('SELECT label, tva_tx, price FROM '.MAIN_DB_PREFIX.'product WHERE rowid = '.$tab_liste[$i]['fk_article']);
$ret=array();
$tab = $db->fetch_array($res);
foreach ( $tab as $cle => $valeur )
@ -175,10 +161,7 @@ switch ($action)
}
$tab_article = $ret;
$res = $db->query(
'SELECT taux
FROM '.MAIN_DB_PREFIX.'c_tva
WHERE rowid = '.$tab_liste[$i]['fk_tva']);
$res = $db->query('SELECT taux FROM '.MAIN_DB_PREFIX.'c_tva WHERE rowid = '.$tab_liste[$i]['fk_tva']);
$ret=array();
$tab = $db->fetch_array($res);
foreach ( $tab as $cle => $valeur )
@ -250,20 +233,6 @@ switch ($action)
$paiement_id = $payment->create($user);
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)
{
$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...
// won't yet work with non-even tzs
function fetchTimezone() {
// FIXME: work around Safari bug
function fetchTimezone()
{
var localclock = new Date();
// returns negative offset from GMT in minutes
var tzRaw = localclock.getTimezoneOffset();