Qual: Standardisation of code. Clean some code.

This commit is contained in:
Laurent Destailleur 2008-02-24 15:51:06 +00:00
parent 8ce7d5193f
commit 72d107a5d0
14 changed files with 162 additions and 256 deletions

View File

@ -649,7 +649,7 @@ if ($_POST['action'] == 'classin')
{ {
$propal = new Propal($db); $propal = new Propal($db);
$propal->fetch($_GET['propalid']); $propal->fetch($_GET['propalid']);
$propal->set_project($user, $_POST['projetidp']); $propal->setProject($_POST['projetidp']);
} }
// Conditions de reglement // Conditions de reglement

View File

@ -36,8 +36,10 @@ require_once(DOL_DOCUMENT_ROOT."/product.class.php");
*/ */
class Commande extends CommonObject class Commande extends CommonObject
{ {
var $db ; var $db;
var $error;
var $element='commande'; var $element='commande';
var $table_element='commande';
var $id ; var $id ;
@ -1997,26 +1999,6 @@ class Commande extends CommonObject
} }
} }
/**
* \brief Classer la commande dans un projet
* \param cat_id Id du projet
*/
function classin($cat_id)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET fk_projet = $cat_id";
$sql .= " WHERE rowid = $this->id;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/** /**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord * \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord

View File

@ -18,15 +18,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/commande/fiche.php \file htdocs/commande/fiche.php
\ingroup commande \ingroup commande
\brief Fiche commande client \brief Fiche commande client
\version $Revision$ \version $Id$
*/ */
require('./pre.inc.php'); require('./pre.inc.php');
@ -121,11 +119,11 @@ if (($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes
} }
// Categorisation dans projet // Categorisation dans projet
if ($_POST['action'] == 'classin' && $user->rights->commande->creer) if ($_POST['action'] == 'classin')
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']);
$commande->classin($_POST['projetid']); $commande->setProject($_POST['projetid']);
} }
// Ajout commande // Ajout commande
@ -708,6 +706,11 @@ if ($_POST['action'] == 'send')
} }
} }
/*
* View
*/
llxHeader('',$langs->trans('Order'),'Commande'); llxHeader('',$langs->trans('Order'),'Commande');
$html = new Form($db); $html = new Form($db);

View File

@ -562,6 +562,37 @@ class CommonObject
return $contactAlreadySelected; return $contactAlreadySelected;
} }
/**
* \brief Link ekement with a project
* \param projid Project id to link element to
* \return int <0 if KO, >0 if OK
*/
function setProject($projid)
{
if (! $this->table_element)
{
dolibarr_syslog("CommonObject::setProject was called on objet with property table_element not defined");
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
if ($projid) $sql.= ' SET fk_projet = '.$projid;
else $sql.= ' SET fk_projet = NULL';
$sql.= ' WHERE rowid = '.$this->id;
dolibarr_syslog("CommonObject::set_project sql=".$sql);
if ($this->db->query($sql))
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
} }
?> ?>

View File

@ -171,7 +171,7 @@ if ($_POST['action'] == 'classin')
{ {
$facture = new Facture($db); $facture = new Facture($db);
$facture->fetch($_GET['facid']); $facture->fetch($_GET['facid']);
$facture->classin($_POST['projetid']); $facture->setProject($_POST['projetid']);
} }
if ($_POST['action'] == 'setmode') if ($_POST['action'] == 'setmode')
@ -233,13 +233,6 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->facture->creer)
} }
} }
if ($_POST['action'] == 'classin')
{
$facture = new Facture($db);
$facture->fetch($_GET['facid']);
$facture->classin($_POST['projetid']);
}
if ($_POST['action'] == 'set_ref_client') if ($_POST['action'] == 'set_ref_client')
{ {
$facture = new Facture($db); $facture = new Facture($db);

View File

@ -36,7 +36,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/price.lib.php");
class Contrat extends CommonObject class Contrat extends CommonObject
{ {
var $db; var $db;
var $error;
var $element='contrat'; var $element='contrat';
var $table_element='contrat';
var $id; var $id;
var $ref; var $ref;
@ -907,29 +909,6 @@ class Contrat extends CommonObject
} }
/**
* \brief Classe le contrat dans un projet
* \param projid Id du projet dans lequel classer le contrat
*/
function classin($projid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
if ($projid) $sql.= " SET fk_projet = $projid";
else $sql.= " SET fk_projet = NULL";
$sql.= " WHERE rowid = ".$this->id;
if ($this->db->query($sql))
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/** /**
* \brief Mets à jour les commentaires privés * \brief Mets à jour les commentaires privés
* \param note Commentaire * \param note Commentaire

View File

@ -169,7 +169,7 @@ if ($_POST["action"] == 'classin')
{ {
$contrat = new Contrat($db); $contrat = new Contrat($db);
$contrat->fetch($_GET["id"]); $contrat->fetch($_GET["id"]);
$contrat->classin($_POST["projetid"]); $contrat->setProject($_POST["projetid"]);
} }
if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer) if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
@ -1067,7 +1067,7 @@ else
/* /*
* Ajouter une ligne produit/service * Ajouter une ligne produit/service
*/ */
if ($user->rights->contrat->creer && $contrat->statut == 0) if ($user->rights->contrat->creer && ($contrat->statut == 0 || $conf->global->CONTRAT_EDITWHENVALIDATED))
{ {
print '<br>'; print '<br>';
print '<table class="noborder" width="100%">'; // Array with (n*2)+1 lines print '<table class="noborder" width="100%">'; // Array with (n*2)+1 lines
@ -1169,7 +1169,7 @@ else
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if (($contrat->statut == 0 || $conf->global->CONTRAT_EDITWHENVALIDATED) && $nbofservices) if ($contrat->statut == 0 && $nbofservices)
{ {
print '<a class="butAction" href="fiche.php?id='.$id.'&amp;action=valid">'.$langs->trans("Validate").'</a>'; print '<a class="butAction" href="fiche.php?id='.$id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
} }

View File

@ -17,16 +17,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/expedition/expedition.class.php \file htdocs/expedition/expedition.class.php
\ingroup expedition \ingroup expedition
\brief Fichier de la classe de gestion des expeditions \brief Fichier de la classe de gestion des expeditions
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
@ -41,6 +38,10 @@ if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande
class Expedition extends CommonObject class Expedition extends CommonObject
{ {
var $db; var $db;
var $error;
var $element="expedition";
var $table_element="expedition";
var $id; var $id;
var $socid; var $socid;
var $brouillon; var $brouillon;
@ -541,26 +542,6 @@ class Expedition extends CommonObject
} }
} }
/**
* Classe la commande
*
*
*/
function classin($cat_id)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_projet = $cat_id";
$sql .= " WHERE rowid = $this->id;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
/** /**
* \brief Positionne modele derniere generation * \brief Positionne modele derniere generation

View File

@ -678,27 +678,6 @@ class Facture extends CommonObject
} }
/**
* \brief Classe la facture dans un projet
* \param projid Id du projet dans lequel classer la facture
*/
function classin($projid)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
if ($projid) $sql.= ' SET fk_projet = '.$projid;
else $sql.= ' SET fk_projet = NULL';
$sql.= ' WHERE rowid = '.$this->id;
if ($this->db->query($sql))
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
function set_ref_client($ref_client) function set_ref_client($ref_client)
{ {
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
@ -879,7 +858,7 @@ class Facture extends CommonObject
$mois += 1; $mois += 1;
} }
// On se déplace au début du mois suivant, et on retire un jour // On se déplace au début du mois suivant, et on retire un jour
$datelim=mktime(12,0,0,$mois,1,$annee); $datelim=dolibarr_mktime(12,0,0,$mois,1,$annee);
$datelim -= (3600 * 24); $datelim -= (3600 * 24);
} }
@ -1764,41 +1743,17 @@ class Facture extends CommonObject
} }
/**
* \brief Renvoie la liste des sommes de tva
*/
function getSumTva()
{
$tvs=array();
$sql = 'SELECT amount, tva_tx FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$this->id;
if ($this->db->query($sql))
{
$num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$tvs[$row[1]] = $row[0];
$i++;
}
return $tvs;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/** /**
* \brief Renvoie la sommes des paiements deja effectués * \brief Renvoie la sommes des paiements deja effectués
* \return Montant deja versé, <0 si ko * \return Montant deja versé, <0 si ko
*/ */
function getSommePaiement() function getSommePaiement()
{ {
$table='paiement_facture';
if ($element == 'facture_fourn') $table='paiementfourn_facturefourn';
$sql = 'SELECT sum(amount) as amount'; $sql = 'SELECT sum(amount) as amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture'; $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
$sql.= ' WHERE fk_facture = '.$this->id; $sql.= ' WHERE fk_facture = '.$this->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -1921,6 +1876,7 @@ class Facture extends CommonObject
/** /**
* \brief Retourne le libellé du statut d'une facture (brouillon, validée, abandonnée, payée) * \brief Retourne le libellé du statut d'une facture (brouillon, validée, abandonnée, payée)
* \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long
* \param alreadypayed 0=Not payment already done, 1=Some payments already done
* \return string Libelle * \return string Libelle
*/ */
function getLibStatut($mode=0,$alreadypayed=-1) function getLibStatut($mode=0,$alreadypayed=-1)

View File

@ -69,12 +69,12 @@ $mesg='';
* Actions * Actions
*/ */
// Categorisation dans projet // Set project
if ($_POST['action'] == 'classin' && $user->rights->fournisseur->commande->creer) if ($_POST['action'] == 'classin')
{ {
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]); $commande->fetch($_GET["id"]);
$commande->classin($_POST["projetid"]); $commande->setProject($_POST["projetid"]);
} }
if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->commande->creer) if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
@ -601,10 +601,33 @@ else
print '<td colspan="3" width="50%">'; print '<td colspan="3" width="50%">';
print "&nbsp;</td></tr>"; print "&nbsp;</td></tr>";
// Projet
if ($conf->projet->enabled)
{
$langs->load('projects');
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($_GET['action'] != 'classer' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classer&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'classer')
{
$html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'projetid');
}
else
{
$html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'none');
}
print '</td></tr>';
}
// Ligne de 3 colonnes // Ligne de 3 colonnes
print '<tr><td>'.$langs->trans("AmountHT").'</td>'; print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right"><b>'.price($commande->total_ht).'</b></td>'; print '<td align="right"><b>'.price($commande->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td colspan="3">&nbsp;</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td colspan="3">&nbsp;</td></tr>';
print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right">'.price($commande->total_tva).'</td>'; print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right">'.price($commande->total_tva).'</td>';
print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td colspan="3">&nbsp;</td></tr>'; print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td><td colspan="3">&nbsp;</td></tr>';
@ -941,23 +964,6 @@ else
print '</td><td width="50%" valign="top">'; print '</td><td width="50%" valign="top">';
/*
*
*
*/
if ($_GET["action"] == 'classer')
{
print '<form method="post" action="fiche.php?id='.$commande->id.'">';
print '<input type="hidden" name="action" value="classin">';
print '<table class="border">';
print '<tr><td>'.$langs->trans("Project").'</td><td>';
$proj = new Project($db);
$html->select_array("projetid",$proj->liste_array($commande->socid));
print "</td></tr>";
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Send").'"></td></tr></table></form>';
}
/* /*
* *

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr> * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.fr> * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.fr>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
@ -587,7 +587,9 @@ else
if (($fac->paye == 0) && ($fac->statut > 0) && $fac->date_echeance < (time() - $conf->facture->fournisseur->warning_delay)) print img_picto($langs->trans("Late"),"warning"); if (($fac->paye == 0) && ($fac->statut > 0) && $fac->date_echeance < (time() - $conf->facture->fournisseur->warning_delay)) print img_picto($langs->trans("Late"),"warning");
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans('Status').'</td><td colspan="3">'.$fac->getLibStatut(4).'</td></tr>'; // Status
$alreadypayed=$fac->getSommePaiement();
print '<tr><td>'.$langs->trans('Status').'</td><td colspan="3">'.$fac->getLibStatut(4,$alreadypayed).'</td></tr>';
print '<tr><td>'.$langs->trans('AmountHT').'</td><td><b>'.price($fac->total_ht).'</b></td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; print '<tr><td>'.$langs->trans('AmountHT').'</td><td><b>'.price($fac->total_ht).'</b></td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($fac->total_tva).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($fac->total_tva).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
@ -613,7 +615,6 @@ else
$sql .= ' ORDER BY dp DESC'; $sql .= ' ORDER BY dp DESC';
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($result);

View File

@ -16,15 +16,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/fourn/fournisseur.commande.class.php \file htdocs/fourn/fournisseur.commande.class.php
\ingroup fournisseur,commande \ingroup fournisseur,commande
\brief Fichier des classes des commandes fournisseurs \brief Fichier des classes des commandes fournisseurs
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php");
@ -39,6 +37,10 @@ require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
class CommandeFournisseur extends Commande class CommandeFournisseur extends Commande
{ {
var $db ; var $db ;
var $error;
var $element='order_supplier';
var $table_element='commande_fournisseur';
var $id ; var $id ;
var $brouillon; var $brouillon;

View File

@ -40,6 +40,8 @@ class FactureFournisseur extends Facture
var $id; var $id;
var $db; var $db;
var $socid; var $socid;
var $element='facture_fourn';
var $table_element='facture_fourn';
//! 0=brouillon, //! 0=brouillon,
//! 1=validée, //! 1=validée,

View File

@ -43,7 +43,9 @@ require_once(DOL_DOCUMENT_ROOT ."/contact.class.php");
class Propal extends CommonObject class Propal extends CommonObject
{ {
var $db; var $db;
var $error;
var $element='propal'; var $element='propal';
var $table_element='propal';
var $id; var $id;
@ -84,7 +86,6 @@ class Propal extends CommonObject
var $nbtodolate; var $nbtodolate;
var $specimen; var $specimen;
var $error;
/** /**
@ -1192,37 +1193,6 @@ class Propal extends CommonObject
} }
} }
/*
*
*
*
*/
function set_project($user, $project_id)
{
if ($user->rights->propale->creer)
{
//verif que le projet et la soci<63>t<EFBFBD> concordent
$sql = 'SELECT p.rowid, p.title FROM '.MAIN_DB_PREFIX.'projet as p WHERE p.fk_soc ='.$this->socid.' AND p.rowid='.$project_id;
$sqlres = $this->db->query($sql);
if ($sqlres)
{
$numprojet = $this->db->num_rows($sqlres);
if ($numprojet > 0)
{
$this->projetidp=$project_id;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_projet = '.$project_id;
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
$this->db->query($sql);
}
}
else
{
dolibarr_syslog("Propal::set_project Erreur SQL");
}
}
}
/** /**
* \brief Positionne modele derniere generation * \brief Positionne modele derniere generation