2
0
forked from Wavyzz/dolibarr

Fix: No error when no product has been selected on point of sale module.

This commit is contained in:
Laurent Destailleur
2010-07-14 11:19:25 +00:00
parent d4ab29b71f
commit e5e80de504
5 changed files with 81 additions and 56 deletions

View File

@@ -32,10 +32,10 @@
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
// Change this following line to use the correct relative path (../, ../../, etc) // Change this following line to use the correct relative path (../, ../../, etc)
require("../main.inc.php"); require("../main.inc.php");

View File

@@ -1,6 +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) 2008 Laurent Destailleur <eldy@uers.sourceforge.net> * Copyright (C) 2008-2010 Laurent Destailleur <eldy@uers.sourceforge.net>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -28,18 +28,18 @@ include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
class Facturation { class Facturation {
/** /**
* Attributs "volatiles" : r<EFBFBD>initialis<EFBFBD>s apr<EFBFBD>s chaque traitement d'un article * Attributs "volatiles" : reinitialises apres chaque traitement d'un article
* <p>Attributs "volatiles" : r<EFBFBD>initialis<EFBFBD>s apr<EFBFBD>s chaque traitement d'un article</p> * <p>Attributs "volatiles" : reinitialises apres chaque traitement d'un article</p>
* @var int $id => 'rowid' du produit dans llx_product * @var int $id => 'rowid' du produit dans llx_product
* @var string $ref => 'ref' du produit dans llx_product * @var string $ref => 'ref' du produit dans llx_product
* @var int $qte => Quantit<EFBFBD> pour le produit en cours de traitement * @var int $qte => Quantite pour le produit en cours de traitement
* @var int $stock => Stock th<EFBFBD>orique pour le produit en cours de traitement * @var int $stock => Stock theorique pour le produit en cours de traitement
* @var int $remise_percent => Remise en pourcent sur le produit en cours * @var int $remise_percent => Remise en pourcent sur le produit en cours
* @var int $montant_remise => Remise en pourcent sur le produit en cours * @var int $montant_remise => Remise en pourcent sur le produit en cours
* @var int $prix => Prix HT du produit en cours * @var int $prix => Prix HT du produit en cours
* @var int $tva => 'rowid' du taux de tva dans llx_c_tva * @var int $tva => 'rowid' du taux de tva dans llx_c_tva
*/ */
protected $id; var $id;
protected $ref; protected $ref;
protected $qte; protected $qte;
protected $stock; protected $stock;
@@ -86,11 +86,11 @@ class Facturation {
public function ajoutArticle() public function ajoutArticle()
{ {
global $db; global $db;
$sql = "SELECT taux"; $sql = "SELECT taux";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva";
$sql.= " WHERE rowid = ".$this->tva(); $sql.= " WHERE rowid = ".$this->tva();
dol_syslog("ajoutArticle sql=".$sql); dol_syslog("ajoutArticle sql=".$sql);
$resql = $db->query($sql); $resql = $db->query($sql);
@@ -104,7 +104,7 @@ class Facturation {
{ {
dol_print_error($db); dol_print_error($db);
} }
// Define part of HT, VAT, TTC // Define part of HT, VAT, TTC
$resultarray=calcul_price_total($this->qte,$this->prix(),$this->remise_percent(),$vat_rate,0,0,0,'HT',0); $resultarray=calcul_price_total($this->qte,$this->prix(),$this->remise_percent(),$vat_rate,0,0,0,'HT',0);
@@ -113,7 +113,7 @@ class Facturation {
$total_ht = $resultarray[0]; $total_ht = $resultarray[0];
$total_vat = $resultarray[1]; $total_vat = $resultarray[1];
$total_ttc = $resultarray[2]; $total_ttc = $resultarray[2];
// Calcul du montant de la remise // Calcul du montant de la remise
if ($this->remise_percent()) if ($this->remise_percent())
{ {
@@ -141,10 +141,10 @@ class Facturation {
$sql.= ", ".price2num($total_ht,'MT'); $sql.= ", ".price2num($total_ht,'MT');
$sql.= ", ".price2num($total_ttc,'MT'); $sql.= ", ".price2num($total_ttc,'MT');
$sql.= ")"; $sql.= ")";
dol_syslog("ajoutArticle sql=".$sql); dol_syslog("ajoutArticle sql=".$sql);
$result = $db->query($sql); $result = $db->query($sql);
if (!$result) if (!$result)
{ {
dol_print_error($db); dol_print_error($db);
@@ -160,11 +160,11 @@ class Facturation {
public function supprArticle($aArticle) public function supprArticle($aArticle)
{ {
global $db; global $db;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."tmp_caisse"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."tmp_caisse";
$sql.= " WHERE id = ".$aArticle; $sql.= " WHERE id = ".$aArticle;
$sql.= " LIMIT 1"; $sql.= " LIMIT 1";
$db->query($sql); $db->query($sql);
} }
@@ -175,7 +175,7 @@ class Facturation {
public function calculTotaux() public function calculTotaux()
{ {
global $db; global $db;
$res = $db->query ('SELECT remise, total_ht, total_ttc, taux FROM '.MAIN_DB_PREFIX.'tmp_caisse as c $res = $db->query ('SELECT remise, total_ht, total_ttc, taux FROM '.MAIN_DB_PREFIX.'tmp_caisse as c
LEFT JOIN '.MAIN_DB_PREFIX.'c_tva as t ON c.fk_tva = t.rowid LEFT JOIN '.MAIN_DB_PREFIX.'c_tva as t ON c.fk_tva = t.rowid
ORDER BY id'); ORDER BY id');

View File

@@ -19,15 +19,30 @@
/** /**
* This page is called each time we press a key in the code or description * This page is called each time we press a key in the code or description
* search form to show product combo list * search form to show product combo list.
*/ */
include('../master.inc.php');
require ('include/environnement.php');
$langs->load("@cashdesk");
// Verification //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
if ( strlen ($_GET["code"]) >= 0 ) // If at least one key //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
//if (! defined("NOLOGIN")) define("NOLOGIN",'1');
// Change this following line to use the correct relative path (../, ../../, etc)
require("../main.inc.php");
require(DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php');
//header("Content-type: text/html; charset=UTF-8");
header("Content-type: text/html; charset=".$conf->file->character_set_client);
// Search from criteria
if ( strlen ($_GET["code"]) >= 0 ) // If search criteria is on char length at least
{ {
$sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx"; $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
@@ -37,7 +52,7 @@ if ( strlen ($_GET["code"]) >= 0 ) // If at least one key
$sql.= " AND p.fk_product_type = 0"; $sql.= " AND p.fk_product_type = 0";
$sql.= " AND (p.ref LIKE '%".$_GET['code']."%' OR p.label LIKE '%".$_GET['code']."%')"; $sql.= " AND (p.ref LIKE '%".$_GET['code']."%' OR p.label LIKE '%".$_GET['code']."%')";
$sql.= " ORDER BY label"; $sql.= " ORDER BY label";
dol_syslog("facturation_dhtml.php sql=".$sql); dol_syslog("facturation_dhtml.php sql=".$sql);
$result = $db->query($sql); $result = $db->query($sql);
@@ -46,7 +61,7 @@ if ( strlen ($_GET["code"]) >= 0 ) // If at least one key
if ( $nbr = $db->num_rows($result) ) if ( $nbr = $db->num_rows($result) )
{ {
$resultat = '<ul class="dhtml_bloc">'; $resultat = '<ul class="dhtml_bloc">';
$ret=array(); $i=0; $ret=array(); $i=0;
while ( $tab = $db->fetch_array($result) ) while ( $tab = $db->fetch_array($result) )
{ {
@@ -57,23 +72,25 @@ if ( strlen ($_GET["code"]) >= 0 ) // If at least one key
$i++; $i++;
} }
$tab=$ret; $tab=$ret;
for ( $i = 0; $i < count ($tab); $i++ ) for ( $i = 0; $i < count ($tab); $i++ )
{ {
$resultat .= ' $resultat .= '
<li class="dhtml_defaut" title="'.$tab[$i]['ref'].'" <li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
onMouseOver="javascript: this.className = \'dhtml_selection\';" onMouseOver="javascript: this.className = \'dhtml_selection\';"
onMouseOut="javascript: this.className = \'dhtml_defaut\';" onMouseOut="javascript: this.className = \'dhtml_defaut\';"
">'.htmlentities($tab[$i]['ref'].' - '.$tab[$i]['label']).'</li> >'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</li>
'; ';
} }
$resultat .= '</ul>'; $resultat .= '</ul>';
print $resultat; print $resultat;
} }
else else
{ {
$langs->load("cashdesk@cashdesk");
print '<ul class="dhtml_bloc">'; print '<ul class="dhtml_bloc">';
print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>'; print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
print '</ul>'; print '</ul>';

View File

@@ -1,6 +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) 2008 Laurent Destailleur <eldy@uers.sourceforge.net> * Copyright (C) 2008-2010 Laurent Destailleur <eldy@uers.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
@@ -18,8 +18,8 @@
*/ */
require ('../master.inc.php'); require ('../master.inc.php');
require ('include/environnement.php'); require (DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php');
require ('class/Facturation.class.php'); require (DOL_DOCUMENT_ROOT.'/cashdesk/class/Facturation.class.php');
$obj_facturation = unserialize ($_SESSION['serObjFacturation']); $obj_facturation = unserialize ($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']); unset ($_SESSION['serObjFacturation']);
@@ -34,7 +34,7 @@ switch ( $_GET['action'] )
if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = ".$conf_fkentrepot; if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = ".$conf_fkentrepot;
// Recuperation des donnees en fonction de la source (liste deroulante ou champ texte) ... // Recuperation des donnees en fonction de la source (liste deroulante ou champ texte) ...
if ( $_POST['hdnSource'] == 'LISTE' ) if ( $_POST['hdnSource'] == 'LISTE' )
{ {
@@ -44,9 +44,9 @@ switch ( $_GET['action'] )
{ {
$sql.= " WHERE p.ref = '".$_POST['txtRef']."'"; $sql.= " WHERE p.ref = '".$_POST['txtRef']."'";
} }
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
// ... et enregistrement dans l'objet // ... et enregistrement dans l'objet
@@ -58,13 +58,13 @@ switch ( $_GET['action'] )
{ {
$ret[$key] = $value; $ret[$key] = $value;
} }
$obj_facturation->id( $ret['rowid'] ); $obj_facturation->id( $ret['rowid'] );
$obj_facturation->ref( $ret['ref'] ); $obj_facturation->ref( $ret['ref'] );
$obj_facturation->stock( $ret['reel'] ); $obj_facturation->stock( $ret['reel'] );
$obj_facturation->prix( $ret['price'] ); $obj_facturation->prix( $ret['price'] );
$obj_facturation->tva( $ret['tva_tx'] ); $obj_facturation->tva( $ret['tva_tx'] );
// Definition du filtre pour n'afficher que le produit concerne // Definition du filtre pour n'afficher que le produit concerne
if ( $_POST['hdnSource'] == 'LISTE' ) if ( $_POST['hdnSource'] == 'LISTE' )
{ {
@@ -74,13 +74,13 @@ switch ( $_GET['action'] )
{ {
$filtre = $_POST['txtRef']; $filtre = $_POST['txtRef'];
} }
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre; $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre;
} }
else else
{ {
$obj_facturation->raz(); $obj_facturation->raz();
if ( $_POST['hdnSource'] == 'REF' ) if ( $_POST['hdnSource'] == 'REF' )
{ {
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef']; $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef'];
@@ -101,22 +101,30 @@ switch ( $_GET['action'] )
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
} }
break; break;
case 'ajout_article': case 'ajout_article': // We have clicked on button "Add product"
$obj_facturation->qte($_POST['txtQte']);
$obj_facturation->tva($_POST['selTva']);
$obj_facturation->remise_percent($_POST['txtRemise']);
$obj_facturation->ajoutArticle();
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; //var_dump($obj_facturation);
break; //exit;
if (! empty($obj_facturation->id)) // A product has been selected and stored in session
{
$obj_facturation->qte($_POST['txtQte']);
$obj_facturation->tva($_POST['selTva']);
$obj_facturation->remise_percent($_POST['txtRemise']);
$obj_facturation->ajoutArticle();
}
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
break;
case 'suppr_article': case 'suppr_article':
$obj_facturation->supprArticle($_GET['suppr_id']); $obj_facturation->supprArticle($_GET['suppr_id']);
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
break; break;
} }

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2007-2008 J<EFBFBD>r<EFBFBD>mie Ollivier <jeremie.o@laposte.net> /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.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
@@ -51,7 +51,7 @@ function file (fichier) {
} }
// Affichage des donn<EFBFBD>es aTexte dans le bloc identifi<EFBFBD> par aId // Affichage des donnees aTexte dans le bloc identifie par aId
function afficheDonnees (aId, aTexte) { function afficheDonnees (aId, aTexte) {
document.getElementById(aId).innerHTML = aTexte; document.getElementById(aId).innerHTML = aTexte;
@@ -59,7 +59,7 @@ function afficheDonnees (aId, aTexte) {
} }
// aCible : id du bloc de destination; aCode : argument <EFBFBD> passer <EFBFBD> la page php charg<EFBFBD>e du traitement et de l'affichage // aCible : id du bloc de destination; aCode : argument a passer a la page php chargee du traitement et de l'affichage
function verifResultat (aCible, aCode) { function verifResultat (aCible, aCode) {
if (aCode != '') { if (aCode != '') {
@@ -76,7 +76,7 @@ function verifResultat (aCible, aCode) {
} }
// Change dynamiquement la classe de l'<EFBFBD>l<EFBFBD>ment ayant l'id aIdElement pour aClasse // Change dynamiquement la classe de l'element ayant l'id aIdElement pour aClasse
function setStyle (aIdElement, aClasse) { function setStyle (aIdElement, aClasse) {
aIdElement.className = aClasse; aIdElement.className = aClasse;