diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index e76782cf1b3..11ee150b581 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -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 diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 73a4954bdb7..3391afeec00 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -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 diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 6c89ab8823b..5cf04aaeca1 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -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); diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 0e6032b1ca0..e45d0c32851 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -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; + } + } + } ?> diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a2cfe225cdb..835a6f05fb0 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -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); diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index fccab983c9c..14c7d227c96 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -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 diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index ea111f3d848..e2862b8ed0b 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -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 '
'; print ''; // Array with (n*2)+1 lines @@ -1169,7 +1169,7 @@ else { print '
'; - if (($contrat->statut == 0 || $conf->global->CONTRAT_EDITWHENVALIDATED) && $nbofservices) + if ($contrat->statut == 0 && $nbofservices) { print ''.$langs->trans("Validate").''; } diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 65aac8dbf39..c4626c99134 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -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 diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 12a8a1a11d6..814aaad391a 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -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) { diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 7890ed0fc82..613879f7538 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -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 '
"; - // Ligne de 3 colonnes + // Projet + if ($conf->projet->enabled) + { + $langs->load('projects'); + print ''; + } + + // Ligne de 3 colonnes print ''; print ''; print ''; + print ''; print ''; @@ -941,23 +964,6 @@ else print ''; - print ''; + // Status + $alreadypayed=$fac->getSommePaiement(); + print ''; print ''; print ''; @@ -613,7 +615,6 @@ else $sql .= ' ORDER BY dp DESC'; $result = $db->query($sql); - if ($result) { $num = $db->num_rows($result); diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index 969873dd93b..a4db5a53dbf 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -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; diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index c412dfff8c8..3296e2989c8 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -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), diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index d1dfa0190ef..eb46772bd91 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -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�t� 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
'; print " 
'; + print ''; + if ($_GET['action'] != 'classer' && $commande->brouillon) print ''; + print '
'; + print $langs->trans('Project'); + print ''.img_edit($langs->trans('SetProject')).'
'; + print '
'; + 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 '
'.$langs->trans("AmountHT").''.price($commande->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountVAT").''.price($commande->total_tva).''.$langs->trans("Currency".$conf->monnaie).' 
'; - /* - * - * - */ - if ($_GET["action"] == 'classer') - { - print '
'; - print ''; - print ''; - print '"; - print '
'.$langs->trans("Project").''; - - $proj = new Project($db); - $html->select_array("projetid",$proj->liste_array($commande->socid)); - - print "
'; - } /* * diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 1650d10d7ea..da282bacaa8 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2007 Regis Houssin @@ -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 '
'.$langs->trans('Status').''.$fac->getLibStatut(4).'
'.$langs->trans('Status').''.$fac->getLibStatut(4,$alreadypayed).'
'.$langs->trans('AmountHT').''.price($fac->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($fac->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'