A lot of fix on point of sale module

This commit is contained in:
Laurent Destailleur 2009-10-22 00:36:21 +00:00
parent 3cb6df16fd
commit 538736bedb
2 changed files with 159 additions and 132 deletions

View File

@ -54,6 +54,15 @@ else
define('LOG_INFO',6); define('LOG_INFO',6);
define('LOG_DEBUG',7); define('LOG_DEBUG',7);
} }
// Definition of missing functions
if (! function_exists("preg_replace"))
{
function preg_replace($a,$b,$c)
{
}
}
// Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL) // Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL)
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
@ -80,15 +89,16 @@ if (empty($dolibarr_main_data_root))
$dolibarr_main_data_root=str_replace("/htdocs","",$dolibarr_main_document_root); $dolibarr_main_data_root=str_replace("/htdocs","",$dolibarr_main_document_root);
$dolibarr_main_data_root.="/documents"; $dolibarr_main_data_root.="/documents";
} }
// Define some constants // Define some constants
define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem pages php (htdocs) define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem pages php (htdocs)
define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem donnes (documents) define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem donnes (documents)
if ($dolibarr_main_url_root == 'auto' && ! empty($_SERVER["SCRIPT_URL"]) && ! empty($_SERVER["SCRIPT_URI"])) if ($dolibarr_main_url_root == 'auto' && ! empty($_SERVER["SCRIPT_URL"]) && ! empty($_SERVER["SCRIPT_URI"]))
{ {
$dolibarr_main_url_root=preg_replace('/'.$_SERVER["SCRIPT_URL"].'$/i','',$_SERVER["SCRIPT_URI"]); $dolibarr_main_url_root=str_replace($_SERVER["SCRIPT_URL"],'',$_SERVER["SCRIPT_URI"]);
} }
define('DOL_MAIN_URL_ROOT', $dolibarr_main_url_root); // URL relative root define('DOL_MAIN_URL_ROOT', $dolibarr_main_url_root); // URL relative root
$uri=preg_replace('/^http(s?):\/\//i','',$dolibarr_main_url_root); // $suburi contains url without http* $uri=preg_replace('/^http(s?):\/\//i','',$dolibarr_main_url_root); // $uri contains url without http*
$suburi = strstr ($uri, '/'); // $suburi contains url without domain $suburi = strstr ($uri, '/'); // $suburi contains url without domain
if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now '' if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
define('DOL_URL_ROOT', $suburi); // URL relative root ('/', '/dolibarr', ...) define('DOL_URL_ROOT', $suburi); // URL relative root ('/', '/dolibarr', ...)
@ -96,8 +106,9 @@ if (! empty($dolibarr_main_url_root_static)) define('DOL_URL_ROOT_FULL_STATIC',
/* /*
* Controle validite fichier conf * Include functions
*/ */
if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php")) if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"))
{ {
print "Error: Dolibarr config file content seems to be not correctly defined.<br>\n"; print "Error: Dolibarr config file content seems to be not correctly defined.<br>\n";
@ -105,13 +116,9 @@ if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"))
exit; exit;
} }
/*
* Create $conf object
*/
require_once(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"); // Need 970ko memory (1.1 in 2.2) require_once(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"); // Need 970ko memory (1.1 in 2.2)
// If password is encoded, we decode it // If password is encoded, we decode it
if (preg_match('/crypted:/i',$dolibarr_main_db_pass) || ! empty($dolibarr_main_db_encrypted_pass)) if (preg_match('/crypted:/i',$dolibarr_main_db_pass) || ! empty($dolibarr_main_db_encrypted_pass))
{ {
@ -126,6 +133,11 @@ if (preg_match('/crypted:/i',$dolibarr_main_db_pass) || ! empty($dolibarr_main_d
} }
//print memory_get_usage(); //print memory_get_usage();
/*
* Create $conf object
*/
require_once(DOL_DOCUMENT_ROOT."/core/conf.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/conf.class.php");
$conf = new Conf(); $conf = new Conf();
@ -284,10 +296,10 @@ if (! defined('NOREQUIREDB'))
if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
{ {
/*print '$_SERVER["GATEWAY_INTERFACE"]='.$_SERVER["GATEWAY_INTERFACE"].'<br>'; /*print '$_SERVER["GATEWAY_INTERFACE"]='.$_SERVER["GATEWAY_INTERFACE"].'<br>';
print 'session_id()='.session_id().'<br>'; print 'session_id()='.session_id().'<br>';
print '$_SESSION["dol_login"]='.$_SESSION["dol_login"].'<br>'; print '$_SESSION["dol_login"]='.$_SESSION["dol_login"].'<br>';
print '$conf->global->MAIN_ONLY_LOGIN_ALLOWED='.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'<br>'; print '$conf->global->MAIN_ONLY_LOGIN_ALLOWED='.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'<br>';
exit;*/ exit;*/
$ok=0; $ok=0;
if ((! session_id() || ! isset($_SESSION["dol_login"])) && ! isset($_POST["username"]) && ! empty($_SERVER["GATEWAY_INTERFACE"])) $ok=1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin) if ((! session_id() || ! isset($_SESSION["dol_login"])) && ! isset($_POST["username"]) && ! empty($_SERVER["GATEWAY_INTERFACE"])) $ok=1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin)
elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1; // We let working pages that is a login submission (login submit, to allow login by admin) elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1; // We let working pages that is a login submission (login submit, to allow login by admin)
@ -408,4 +420,19 @@ if (! defined('MAGPIE_CACHE_DIR')) { define('MAGPIE_CACHE_DIR', $conf->exte
if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR'); if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR');
/**
* Convert a string into a regex
*
* @param unknown_type $s string to convert
*/
function dol_regify($s)
{
$news=str_replace('/','\/',$s);
$news=str_replace('.','\.',$news);
$news=str_replace('*','\*',$news);
return $news;
}
?> ?>

View File

@ -19,17 +19,17 @@
*/ */
/** /**
\file htdocs/paiement.class.php \file htdocs/paiement.class.php
\ingroup facture \ingroup facture
\brief Fichier de la classe des paiement de factures clients \brief Fichier de la classe des paiement de factures clients
\remarks Cette classe est presque identique a paiementfourn.class.php \remarks Cette classe est presque identique a paiementfourn.class.php
\version $Id$ \version $Id$
*/ */
/** \class Paiement /** \class Paiement
\brief Classe permettant la gestion des paiements des factures clients \brief Classe permettant la gestion des paiements des factures clients
*/ */
class Paiement class Paiement
{ {
@ -41,8 +41,8 @@ class Paiement
var $total; var $total;
var $author; var $author;
var $paiementid; // Type de paiement. Stocke dans fk_paiement var $paiementid; // Type de paiement. Stocke dans fk_paiement
// de llx_paiement qui est lie aux types de // de llx_paiement qui est lie aux types de
//paiement de llx_c_paiement //paiement de llx_c_paiement
var $num_paiement; // Numero du CHQ, VIR, etc... var $num_paiement; // Numero du CHQ, VIR, etc...
var $bank_account; // Id compte bancaire du paiement var $bank_account; // Id compte bancaire du paiement
var $bank_line; // Id de la ligne d'ecriture bancaire var $bank_line; // Id de la ligne d'ecriture bancaire
@ -62,12 +62,12 @@ class Paiement
$this->db = $DB ; $this->db = $DB ;
} }
/** /**
* \brief Recupere l'objet paiement * \brief Recupere l'objet paiement
* \param id id du paiement a recuperer * \param id id du paiement a recuperer
* \return int <0 si ko, 0 si non trouve, >0 si ok * \return int <0 si ko, 0 si non trouve, >0 si ok
*/ */
function fetch($id) function fetch($id)
{ {
$sql = 'SELECT p.rowid,'.$this->db->pdate('p.datep').' as dp, p.amount, p.statut, p.fk_bank'; $sql = 'SELECT p.rowid,'.$this->db->pdate('p.datep').' as dp, p.amount, p.statut, p.fk_bank';
$sql.= ', c.code as type_code, c.libelle as type_libelle'; $sql.= ', c.code as type_code, c.libelle as type_libelle';
@ -88,6 +88,7 @@ class Paiement
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->date = $obj->dp; $this->date = $obj->dp;
$this->datepaye = $obj->dp;
$this->numero = $obj->num_paiement; $this->numero = $obj->num_paiement;
$this->bank_account = $obj->fk_account; $this->bank_account = $obj->fk_account;
$this->bank_line = $obj->fk_bank; $this->bank_line = $obj->fk_bank;
@ -114,9 +115,9 @@ class Paiement
} }
/** /**
* \brief Creation du paiement en base * \brief Create payment in database
* \param user object utilisateur qui cree * \param user object user
* \return int id du paiement cree, < 0 si erreur * \return int id of created payment, < 0 if error
*/ */
function create($user) function create($user)
{ {
@ -124,14 +125,13 @@ class Paiement
$error = 0; $error = 0;
// Nettoyage parametres // Clean parameters
$this->total = 0; $this->total = 0;
foreach ($this->amounts as $key => $value) foreach ($this->amounts as $key => $value) // How payment is dispatch
{ {
$value = price2num($value); $value = price2num($value,'MT');
$val = round($value, 2); $this->amounts[$key] = $value;
$this->amounts[$key] = $val; $this->total += $value;
$this->total += $val;
} }
$this->total = price2num($this->total); $this->total = price2num($this->total);
@ -157,7 +157,7 @@ class Paiement
{ {
$amount = price2num($amount); $amount = price2num($amount);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')'; $sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\')';
dol_syslog("Paiement::Create insert paiement_facture sql=".$sql); dol_syslog("Paiement::Create insert paiement_facture sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -170,18 +170,18 @@ class Paiement
} }
else else
{ {
dol_syslog('Paiement::Create Montant non numérique'); dol_syslog('Paiement::Create Montant non numerique');
} }
} }
if (! $error) if (! $error)
{ {
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('PAYMENT_CUSTOMER_CREATE',$this,$user,$langs,$conf); $result=$interface->run_triggers('PAYMENT_CUSTOMER_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
} }
} }
else else
@ -205,51 +205,51 @@ class Paiement
} }
/** /**
* \brief Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * \brief Supprime un paiement ainsi que les lignes qu'il a genere dans comptes
* Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse
* Si le paiement porte sur au moins une facture a "payee", on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function delete() function delete()
{ {
$bank_line_id = $this->bank_line; $bank_line_id = $this->bank_line;
$this->db->begin(); $this->db->begin();
// Verifier si paiement porte pas sur une facture classee // Verifier si paiement porte pas sur une facture classee
// Si c'est le cas, on refuse la suppression // Si c'est le cas, on refuse la suppression
$billsarray=$this->getBillsArray('fk_statut > 1'); $billsarray=$this->getBillsArray('fk_statut > 1');
if (is_array($billsarray)) if (is_array($billsarray))
{ {
if (sizeof($billsarray)) if (sizeof($billsarray))
{ {
$this->error="Impossible de supprimer un paiement portant sur au moins une facture fermee"; $this->error="Impossible de supprimer un paiement portant sur au moins une facture fermee";
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
// Verifier si paiement ne porte pas sur ecriture bancaire rapprochee // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
// Si c'est le cas, on refuse le paiement // Si c'est le cas, on refuse le paiement
if ($bank_line_id) if ($bank_line_id)
{ {
$accline = new AccountLine($this->db,$bank_line_id); $accline = new AccountLine($this->db,$bank_line_id);
$accline->fetch($bank_line_id); $accline->fetch($bank_line_id);
if ($accline->rappro) if ($accline->rappro)
{ {
$this->error="Impossible de supprimer un paiement qui a genere une ecriture qui a ete rapprochee"; $this->error="Impossible de supprimer un paiement qui a genere une ecriture qui a ete rapprochee";
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
} }
// Efface la ligne de paiement (dans paiement_facture et paiement) // Efface la ligne de paiement (dans paiement_facture et paiement)
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture'; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
$sql.= ' WHERE fk_paiement = '.$this->id; $sql.= ' WHERE fk_paiement = '.$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
@ -258,29 +258,29 @@ class Paiement
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement'; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (! $result) if (! $result)
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
// Supprimer l'ecriture bancaire si paiement lie a ecriture // Supprimer l'ecriture bancaire si paiement lie a ecriture
if ($bank_line_id) if ($bank_line_id)
{ {
$accline = new AccountLine($this->db); $accline = new AccountLine($this->db);
$accline->fetch($bank_line_id); $accline->fetch($bank_line_id);
$result=$accline->delete(); $result=$accline->delete();
if ($result < 0) if ($result < 0)
{ {
$this->error=$accline->error; $this->error=$accline->error;
$this->db->rollback(); $this->db->rollback();
return -4; return -4;
} }
} }
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
@ -290,10 +290,10 @@ class Paiement
} }
} }
/** /**
* \brief Mise a jour du lien entre le paiement et la ligne generee dans llx_bank * \brief Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
* \param id_bank Id compte bancaire * \param id_bank Id compte bancaire
*/ */
function update_fk_bank($id_bank) function update_fk_bank($id_bank)
{ {
$sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank; $sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank;
@ -310,10 +310,10 @@ class Paiement
} }
} }
/** /**
* \brief Valide le paiement * \brief Valide le paiement
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function valide() function valide()
{ {
$sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id; $sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id;
@ -331,11 +331,11 @@ class Paiement
} }
} }
/* /*
* \brief Information sur l'objet * \brief Information sur l'objet
* \param id id du paiement dont il faut afficher les infos * \param id id du paiement dont il faut afficher les infos
*/ */
function info($id) function info($id)
{ {
$sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec, fk_user_creat, fk_user_modif'; $sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec, fk_user_creat, fk_user_modif';
$sql .= ', '.$this->db->pdate('tms').' as tms'; $sql .= ', '.$this->db->pdate('tms').' as tms';
@ -374,11 +374,11 @@ class Paiement
} }
} }
/** /**
* \brief Retourne la liste des factures sur lesquels porte le paiement * \brief Retourne la liste des factures sur lesquels porte le paiement
* \param filter Critere de filtre * \param filter Critere de filtre
* \return array Tableau des id de factures * \return array Tableau des id de factures
*/ */
function getBillsArray($filter='') function getBillsArray($filter='')
{ {
$sql = 'SELECT fk_facture'; $sql = 'SELECT fk_facture';
@ -388,22 +388,22 @@ class Paiement
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$i=0; $i=0;
$num=$this->db->num_rows($resql); $num=$this->db->num_rows($resql);
$billsarray=array(); $billsarray=array();
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$billsarray[$i]=$obj->fk_facture; $billsarray[$i]=$obj->fk_facture;
$i++; $i++;
} }
return $billsarray; return $billsarray;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog('Paiement::getBillsArray Error '.$this->error.' - sql='.$sql); dol_syslog('Paiement::getBillsArray Error '.$this->error.' - sql='.$sql);
return -1; return -1;
} }
@ -432,21 +432,21 @@ class Paiement
} }
/** /**
* \brief Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) * \brief Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* \return string Libelle * \return string Libelle
*/ */
function getLibStatut($mode=0) function getLibStatut($mode=0)
{ {
return $this->LibStatut($this->statut,$mode); return $this->LibStatut($this->statut,$mode);
} }
/** /**
* \brief Renvoi le libelle d'un statut donne * \brief Renvoi le libelle d'un statut donne
* \param status Statut * \param status Statut
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* \return string Libelle du statut * \return string Libelle du statut
*/ */
function LibStatut($status,$mode=0) function LibStatut($status,$mode=0)
{ {
global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage