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

@ -647,9 +647,9 @@ if ($_REQUEST['action'] == 'builddoc' && $user->rights->propale->creer)
if ($_POST['action'] == 'classin')
{
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->set_project($user, $_POST['projetidp']);
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->setProject($_POST['projetidp']);
}
// Conditions de reglement

View File

@ -36,8 +36,10 @@ require_once(DOL_DOCUMENT_ROOT."/product.class.php");
*/
class Commande extends CommonObject
{
var $db ;
var $db;
var $error;
var $element='commande';
var $table_element='commande';
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

View File

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

View File

@ -562,6 +562,37 @@ class CommonObject
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->fetch($_GET['facid']);
$facture->classin($_POST['projetid']);
$facture->setProject($_POST['projetid']);
}
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')
{
$facture = new Facture($db);

View File

@ -36,7 +36,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/price.lib.php");
class Contrat extends CommonObject
{
var $db;
var $error;
var $element='contrat';
var $table_element='contrat';
var $id;
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
* \param note Commentaire

View File

@ -169,7 +169,7 @@ if ($_POST["action"] == 'classin')
{
$contrat = new Contrat($db);
$contrat->fetch($_GET["id"]);
$contrat->classin($_POST["projetid"]);
$contrat->setProject($_POST["projetid"]);
}
if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
@ -1067,7 +1067,7 @@ else
/*
* 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 '<table class="noborder" width="100%">'; // Array with (n*2)+1 lines
@ -1169,7 +1169,7 @@ else
{
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>';
}

View File

@ -17,16 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
/**
\file htdocs/expedition/expedition.class.php
\ingroup expedition
\brief Fichier de la classe de gestion des expeditions
\version $Revision$
\version $Id$
*/
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
{
var $db;
var $error;
var $element="expedition";
var $table_element="expedition";
var $id;
var $socid;
var $brouillon;
@ -55,8 +56,8 @@ class Expedition extends CommonObject
*
*/
function Expedition($DB)
{
global $langs;
{
global $langs;
$this->db = $DB;
$this->lignes = array();
@ -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

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)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
@ -828,66 +807,66 @@ class Facture extends CommonObject
}
/**
\brief Renvoi une date limite de reglement de facture en fonction des
conditions de reglements de la facture et date de facturation
\param cond_reglement_id Condition de reglement à utiliser, 0=Condition actuelle de la facture
\return date Date limite de réglement si ok, <0 si ko
*/
function calculate_date_lim_reglement($cond_reglement_id=0)
{
if (! $cond_reglement_id)
$cond_reglement_id=$this->cond_reglement_id;
$sqltemp = 'SELECT c.fdm,c.nbjour,c.decalage';
$sqltemp.= ' FROM '.MAIN_DB_PREFIX.'cond_reglement as c';
$sqltemp.= ' WHERE c.rowid='.$cond_reglement_id;
$resqltemp=$this->db->query($sqltemp);
if ($resqltemp)
{
if ($this->db->num_rows($resqltemp))
{
$obj = $this->db->fetch_object($resqltemp);
$cdr_nbjour = $obj->nbjour;
$cdr_fdm = $obj->fdm;
$cdr_decalage = $obj->decalage;
}
}
else
{
$this->error=$this->db->error();
return -1;
}
$this->db->free($resqltemp);
/**
\brief Renvoi une date limite de reglement de facture en fonction des
conditions de reglements de la facture et date de facturation
\param cond_reglement_id Condition de reglement à utiliser, 0=Condition actuelle de la facture
\return date Date limite de réglement si ok, <0 si ko
*/
function calculate_date_lim_reglement($cond_reglement_id=0)
{
if (! $cond_reglement_id)
$cond_reglement_id=$this->cond_reglement_id;
$sqltemp = 'SELECT c.fdm,c.nbjour,c.decalage';
$sqltemp.= ' FROM '.MAIN_DB_PREFIX.'cond_reglement as c';
$sqltemp.= ' WHERE c.rowid='.$cond_reglement_id;
$resqltemp=$this->db->query($sqltemp);
if ($resqltemp)
{
if ($this->db->num_rows($resqltemp))
{
$obj = $this->db->fetch_object($resqltemp);
$cdr_nbjour = $obj->nbjour;
$cdr_fdm = $obj->fdm;
$cdr_decalage = $obj->decalage;
}
}
else
{
$this->error=$this->db->error();
return -1;
}
$this->db->free($resqltemp);
/* Definition de la date limite */
/* Definition de la date limite */
// 1 : ajout du nombre de jours
$datelim = $this->date + ( $cdr_nbjour * 3600 * 24 );
// 1 : ajout du nombre de jours
$datelim = $this->date + ( $cdr_nbjour * 3600 * 24 );
// 2 : application de la règle "fin de mois"
if ($cdr_fdm)
{
$mois=date('m', $datelim);
$annee=date('Y', $datelim);
if ($mois == 12)
{
$mois = 1;
$annee += 1;
}
else
{
$mois += 1;
}
// On se déplace au début du mois suivant, et on retire un jour
$datelim=mktime(12,0,0,$mois,1,$annee);
$datelim -= (3600 * 24);
}
// 2 : application de la règle "fin de mois"
if ($cdr_fdm)
{
$mois=date('m', $datelim);
$annee=date('Y', $datelim);
if ($mois == 12)
{
$mois = 1;
$annee += 1;
}
else
{
$mois += 1;
}
// On se déplace au début du mois suivant, et on retire un jour
$datelim=dolibarr_mktime(12,0,0,$mois,1,$annee);
$datelim -= (3600 * 24);
}
// 3 : application du décalage
$datelim += ( $cdr_decalage * 3600 * 24);
// 3 : application du décalage
$datelim += ( $cdr_decalage * 3600 * 24);
return $datelim;
}
return $datelim;
}
/**
* \brief Tag la facture comme payée complètement (close_code non renseigné) ou partiellement (close_code renseigné) + appel trigger BILL_PAYED
@ -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
* \return Montant deja versé, <0 si ko
*/
function getSommePaiement()
{
$table='paiement_facture';
if ($element == 'facture_fourn') $table='paiementfourn_facturefourn';
$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;
$resql=$this->db->query($sql);
if ($resql)
@ -1919,9 +1874,10 @@ class Facture extends CommonObject
/**
* \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
* \return string Libelle
* \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 alreadypayed 0=Not payment already done, 1=Some payments already done
* \return string Libelle
*/
function getLibStatut($mode=0,$alreadypayed=-1)
{

View File

@ -69,12 +69,12 @@ $mesg='';
* Actions
*/
// Categorisation dans projet
if ($_POST['action'] == 'classin' && $user->rights->fournisseur->commande->creer)
// Set project
if ($_POST['action'] == 'classin')
{
$commande = new CommandeFournisseur($db);
$commande->fetch($_GET["id"]);
$commande->classin($_POST["projetid"]);
$commande->setProject($_POST["projetid"]);
}
if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
@ -601,10 +601,33 @@ else
print '<td colspan="3" width="50%">';
print "&nbsp;</td></tr>";
// Ligne de 3 colonnes
// 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
print '<tr><td>'.$langs->trans("AmountHT").'</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 '<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>';
@ -941,23 +964,6 @@ else
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
/* 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) 2005 Marc Barilley / Ocebo <marc@ocebo.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");
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('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';
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);

View File

@ -16,15 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
/**
\file htdocs/fourn/fournisseur.commande.class.php
\ingroup fournisseur,commande
\brief Fichier des classes des commandes fournisseurs
\version $Revision$
\version $Id$
*/
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
{
var $db ;
var $error;
var $element='order_supplier';
var $table_element='commande_fournisseur';
var $id ;
var $brouillon;

View File

@ -40,7 +40,9 @@ class FactureFournisseur extends Facture
var $id;
var $db;
var $socid;
var $element='facture_fourn';
var $table_element='facture_fourn';
//! 0=brouillon,
//! 1=validée,
//! TODO Ce statut doit etre 2 et non 1 classée payée partiellement (close_code='discount_vat','badcustomer') ou complètement (close_code=null),

View File

@ -43,7 +43,9 @@ require_once(DOL_DOCUMENT_ROOT ."/contact.class.php");
class Propal extends CommonObject
{
var $db;
var $error;
var $element='propal';
var $table_element='propal';
var $id;
@ -84,7 +86,6 @@ class Propal extends CommonObject
var $nbtodolate;
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