From 935431eba32b5713f9e8ad647bd60343857a56b3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jan 2010 23:21:22 +0000 Subject: [PATCH] New: Support note on trips module --- ChangeLog | 1 + .../compta/deplacement/deplacement.class.php | 49 +++-- htdocs/compta/deplacement/fiche.php | 29 +-- htdocs/compta/deplacement/note.php | 202 ++++++++++++++++++ htdocs/compta/deplacement/pre.inc.php | 12 +- htdocs/compta/facture.php | 38 +++- htdocs/compta/facture/note.php | 2 +- htdocs/compta/paiement/fiche.php | 23 +- htdocs/compta/pre.inc.php | 16 +- htdocs/facture.class.php | 2 +- .../install/mysql/migration/2.7.0-2.8.0.sql | 1 + .../install/mysql/tables/llx_deplacement.sql | 3 +- 12 files changed, 314 insertions(+), 64 deletions(-) create mode 100644 htdocs/compta/deplacement/note.php diff --git a/ChangeLog b/ChangeLog index 45e7ee0bf93..497db948f30 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ English Dolibarr ChangeLog ***** ChangeLog for 2.8 compared to 2.7 ***** For users: +- New: Support note on trips module - New: Can link contacts to projects - New: Can removed attached file on email form if attachment was wrong. - New: Add option to show your logo on top of left menu. diff --git a/htdocs/compta/deplacement/deplacement.class.php b/htdocs/compta/deplacement/deplacement.class.php index b297e191920..7b164ed5aa4 100644 --- a/htdocs/compta/deplacement/deplacement.class.php +++ b/htdocs/compta/deplacement/deplacement.class.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2009 Regis Houssin - * + * * 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 * the Free Software Foundation; either version 2 of the License, or @@ -34,16 +34,22 @@ require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); class Deplacement extends CommonObject { var $db; - var $errors; - + var $error; + var $element='deplacement'; + var $table_element='deplacement'; + var $table_element_line = ''; + var $fk_element = ''; + var $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + var $id; var $fk_user_author; var $fk_user; var $km; var $note; + var $note_public; var $socid; - - + + /** * \brief Constructeur de la classe * \param DB handler acces base de donnees @@ -66,7 +72,7 @@ class Deplacement extends CommonObject function create($user) { global $conf; - + // Check parameters if (empty($this->type) || $this->type < 0) { @@ -78,21 +84,25 @@ class Deplacement extends CommonObject $this->error='ErrorBadParameter'; return -1; } - + $this->db->begin(); - + $sql = "INSERT INTO ".MAIN_DB_PREFIX."deplacement ("; $sql.= "datec"; $sql.= ", entity"; $sql.= ", fk_user_author"; $sql.= ", fk_user"; $sql.= ", type"; + $sql.= ", note"; + $sql.= ", note_public"; $sql.= ") VALUES ("; $sql.= $this->db->idate(mktime()); $sql.= ", ".$conf->entity; $sql.= ", ".$user->id; $sql.= ", ".$this->fk_user; $sql.= ", '".$this->type."'"; + $sql.= ", note = ".($this->note?"'".addslashes($this->note)."'":"null"); + $sql.= ", note_public = ".($this->note_public?"'".addslashes($this->note_public)."'":"null"); $sql.= ")"; dol_syslog("Deplacement::create sql=".$sql, LOG_DEBUG); @@ -116,13 +126,13 @@ class Deplacement extends CommonObject { $this->error=$this->db->error()." sql=".$sql; $this->db->rollback(); - return -1; + return -1; } - + } /** - * + * */ function update($user) { @@ -130,7 +140,7 @@ class Deplacement extends CommonObject // Clean parameters $this->km=price2num($this->km); - + // Check parameters if (! is_numeric($this->km)) $this->km = 0; if (empty($this->type) || $this->type < 0) @@ -143,13 +153,15 @@ class Deplacement extends CommonObject $this->error='ErrorBadParameter'; return -1; } - + $sql = "UPDATE ".MAIN_DB_PREFIX."deplacement "; $sql .= " SET km = ".$this->km; // This is a distance or amount $sql .= " , dated = '".$this->db->idate($this->date)."'"; $sql .= " , type = '".$this->type."'"; $sql .= " , fk_user = ".$this->fk_user; $sql .= " , fk_soc = ".($this->socid > 0?$this->socid:'null'); + $sql .= " , note = ".($this->note?"'".addslashes($this->note)."'":"null"); + $sql .= " , note_public = ".($this->note_public?"'".addslashes($this->note_public)."'":"null"); $sql .= " WHERE rowid = ".$this->id; dol_syslog("Deplacement::update sql=".$sql, LOG_DEBUG); @@ -166,11 +178,11 @@ class Deplacement extends CommonObject } /** - * + * Load an object from database */ function fetch($id) { - $sql = "SELECT rowid, fk_user, type, km, fk_soc,".$this->db->pdate("dated")." as dated"; + $sql = "SELECT rowid, fk_user, type, km, fk_soc, dated, note, note_public"; $sql.= " FROM ".MAIN_DB_PREFIX."deplacement"; $sql.= " WHERE rowid = ".$id; @@ -182,11 +194,13 @@ class Deplacement extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; - $this->date = $obj->dated; + $this->date = $this->db->jdate($obj->dated); $this->fk_user = $obj->fk_user; $this->socid = $obj->fk_soc; $this->km = $obj->km; $this->type = $obj->type; + $this->note = $obj->note; + $this->note_public = $obj->note_public; return 1; } @@ -204,6 +218,7 @@ class Deplacement extends CommonObject { $sql = "DELETE FROM ".MAIN_DB_PREFIX."deplacement WHERE rowid = ".$id; + dol_syslog("Deplacement::delete sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index 97bffd24d1f..b70ceeb33e4 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -193,17 +193,25 @@ else if ($mesg) print $mesg."
"; + $h=0; + + $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$deplacement->id"; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/note.php?id=$deplacement->id"; + $head[$h][1] = $langs->trans("Note"); + $head[$h][2] = 'note'; + $h++; + + dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); + if ($_GET["action"] == 'edit') { $soc = new Societe($db); $soc->fetch($deplacement->socid); - $h=0; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$deplacement->id"; - $head[$h][1] = $langs->trans("Card"); - - dol_fiche_head($head, $hselected, $langs->trans("TripCard"), 0, 'trip'); print "
\n"; print ''; @@ -246,15 +254,8 @@ else } else { - $h=0; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$deplacement->id"; - $head[$h][1] = $langs->trans("Card"); - - dol_fiche_head($head, $hselected, $langs->trans("TripCard"), 0, 'trip'); - /* - * Confirmation de la suppression du d�placement + * Confirmation de la suppression du deplacement */ if ($_GET["action"] == 'delete') { diff --git a/htdocs/compta/deplacement/note.php b/htdocs/compta/deplacement/note.php new file mode 100644 index 00000000000..bf989572f49 --- /dev/null +++ b/htdocs/compta/deplacement/note.php @@ -0,0 +1,202 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + +/** + * \file htdocs/compta/deplacement/note.php + * \ingroup trip + * \brief Notes on a trip card + * \version $Id$ + */ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/deplacement.class.php"); + +$socid=isset($_GET["socid"])?$_GET["socid"]:isset($_POST["socid"])?$_POST["socid"]:""; + +if (!$user->rights->deplacement->lire) + accessforbidden(); + +$langs->load("companies"); +$langs->load("bills"); +$langs->load("trips"); + +// Securiy check +if ($user->societe_id > 0) +{ + unset($_GET["action"]); + $socid = $user->societe_id; +} + + +$trip = new Deplacement($db); + + +/******************************************************************************/ +/* Actions */ +/******************************************************************************/ + +if ($_POST["action"] == 'update_public' && $user->rights->deplacement->creer) +{ + $db->begin(); + + $trip->fetch($_GET["id"]); + + $res=$trip->update_note_public($_POST["note_public"],$user); + if ($res < 0) + { + $mesg='
'.$fac->error.'
'; + $db->rollback(); + } + else + { + $db->commit(); + } +} + +if ($_POST["action"] == 'update' && $user->rights->deplacement->creer) +{ + $db->begin(); + + $trip->fetch($_GET["id"]); + + $res=$trip->update_note($_POST["note"],$user); + if ($res < 0) + { + $mesg='
'.$fac->error.'
'; + $db->rollback(); + } + else + { + $db->commit(); + } +} + + + +/******************************************************************************/ +/* Affichage fiche */ +/******************************************************************************/ + +llxHeader(); + +$html = new Form($db); + +$id = $_GET['id']; +$ref= $_GET['ref']; +if ($id > 0 || ! empty($ref)) +{ + $trip = new Deplacement($db); + $trip->fetch($id,$ref); + + $soc = new Societe($db, $trip->socid); + $soc->fetch($trip->socid); + + $h=0; + + $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$trip->id"; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/note.php?id=$trip->id"; + $head[$h][1] = $langs->trans("Note"); + $head[$h][2] = 'note'; + $h++; + + dol_fiche_head($head, 'note', $langs->trans("TripCard"), 0, 'trip'); + + + print ''; + + // Ref + print ''; + print ''; + + print ''; + + print ''; + print ''; + + // Note publique + print ''; + print '"; + + // Note privee + if (! $user->societe_id) + { + print ''; + print '"; + } + + print "
'.$langs->trans('Ref').''; + $morehtmlref=''; + print $html->showrefnav($trip,'ref','',1,'ref','ref',$morehtmlref); + print '
'.$langs->trans("Type").''.$langs->trans($trip->type).'
'.$langs->trans("CompanyVisited").''; + if ($soc->id) print $soc->getNomUrl(1); + print '
'.$langs->trans("NotePublic").' :'; + if ($_GET["action"] == 'edit') + { + print ''; + print ''; + print ''; + print '
"; + print ''; + print ''; + } + else + { + print ($trip->note_public?nl2br($trip->note_public):" "); + } + print "
'.$langs->trans("NotePrivate").' :'; + if ($_GET["action"] == 'edit') + { + print '
'; + print ''; + print ''; + print '
"; + print ''; + print '
'; + } + else + { + print ($trip->note?nl2br($trip->note):" "); + } + print "
"; + + + /* + * Actions + */ + print ''; + print '
'; + + if ($user->rights->deplacement->creer && $_GET["action"] <> 'edit') + { + print "id&action=edit\">".$langs->trans('Modify').""; + } + + print "
"; + + +} + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/compta/deplacement/pre.inc.php b/htdocs/compta/deplacement/pre.inc.php index 15d1dbc438c..9383069123d 100644 --- a/htdocs/compta/deplacement/pre.inc.php +++ b/htdocs/compta/deplacement/pre.inc.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2004 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -21,11 +21,11 @@ * */ -/** - \file htdocs/compta/deplacement/pre.inc.php - \ingroup deplacement - \brief Fichier gestionnaire du menu deplacement -*/ +/** + * \file htdocs/compta/deplacement/pre.inc.php + * \ingroup deplacement + * \brief Fichier gestionnaire du menu deplacement + */ require("../../main.inc.php"); require("./deplacement.class.php"); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 141d0df7883..de3fb6647f3 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -98,7 +98,8 @@ if ($_GET['action'] == 'reopen' && $user->rights->facture->creer) { $fac = new Facture($db); $result = $fac->fetch($_GET['facid']); - if ($fac->statut == 3 && ($fac->close_code == 'badcustomer' || $fac->close_code == 'abandon')) + if ($fac->statut == 2 + || ($fac->statut == 3 && $fac->close_code != 'replaced')) { $result = $fac->set_unpaid($user); if ($result > 0) @@ -3250,10 +3251,23 @@ else } } + // Reopen a standard paid invoice + if ($fac->type == 1 && $fac->statut == 2) // A paid invoice (partially or completely) + { + if (! $facidnext) + { + print ''.$langs->trans('ReOpen').''; + } + else + { + print ''.$langs->trans('ReOpen').''; + } + } + // Reopen a classified invoice if ($fac->statut == 3 && // A abandoned invoice $fac->getIdReplacingInvoice() == 0 && // Not replaced by another invoice - ($fac->close_code == 'badcustomer' || $fac->close_code == 'abandon')) + $fac->close_code != 'replaced') // Not replaced by another invoice { if (! $facidnext) { @@ -3399,6 +3413,10 @@ else { print ''.$langs->trans('Delete').''; } + elseif ($fac->getSommePaiement()) + { + print ''.$langs->trans('Delete').''; + } else { print ''.$langs->trans('Delete').''; @@ -3721,7 +3739,7 @@ else $sql = 'SELECT '; $sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,'; - $sql.= ' '.$db->pdate('f.datef').' as df, '.$db->pdate('f.date_lim_reglement').' as datelimite,'; + $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; $sql.= ' f.paye as paye, f.fk_statut,'; $sql.= ' s.nom, s.rowid as socid'; if (! $sall) $sql.= ' ,sum(pf.amount) as am'; @@ -3858,6 +3876,8 @@ else $objp = $db->fetch_object($resql); $var=!$var; + $datelimit=$db->jdate($objp->datelimite); + print ''; print ''; @@ -3885,10 +3905,10 @@ else // Date if ($objp->df > 0) { - $y = dol_print_date($objp->df,'%Y'); - $m = dol_print_date($objp->df,'%m'); - $mt = dol_print_date($objp->df,'%b'); - $d = dol_print_date($objp->df,'%d'); + $y = dol_print_date($db->jdate($objp->df),'%Y'); + $m = dol_print_date($db->jdate($objp->df),'%m'); + $mt = dol_print_date($db->jdate($objp->df),'%b'); + $d = dol_print_date($db->jdate($objp->df),'%d'); print ''; print $d; print ' '; @@ -3902,8 +3922,8 @@ else } // Date limit - print ''.dol_print_date($objp->datelimite,'day'); - if ($objp->datelimite < ($now - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) + print ''.dol_print_date($datelimit,'day'); + if ($datelimit < ($now - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am) { print img_warning($langs->trans('Late')); } diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php index 2217601b2a6..dde5790b3f3 100644 --- a/htdocs/compta/facture/note.php +++ b/htdocs/compta/facture/note.php @@ -37,7 +37,7 @@ if (!$user->rights->facture->lire) $langs->load("companies"); $langs->load("bills"); -// S�curit� acc�s +// Security check if ($user->societe_id > 0) { unset($_GET["action"]); diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index a47463d1285..8da328be9b6 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -41,7 +41,7 @@ $langs->load('companies'); $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; if ($user->societe_id) $socid=$user->societe_id; -// TODO ajouter r�gle pour restreindre acces paiement +// TODO ajouter regle pour restreindre acces paiement //$result = restrictedArea($user, 'facture', $id,''); $mesg=''; @@ -206,9 +206,10 @@ print ''; /* - * Liste des factures + * List of invoices */ -$allow_delete = 1 ; + +$disable_delete = 0; $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom, s.rowid as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s'; $sql.= ' WHERE pf.fk_facture = f.rowid'; @@ -251,9 +252,9 @@ if ($resql) print ''.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.''; print ''.price($objp->amount).''; print "\n"; - if ($objp->paye == 1) + if ($objp->paye == 1) // If at least one invoice is paid, disable delete { - $allow_delete = 0; + $disable_delete = 1; } $total = $total + $objp->amount; $i++; @@ -288,11 +289,19 @@ if ($conf->global->BILL_ADD_PAYMENT_VALIDATION) } } } -if ($user->societe_id == 0 && $allow_delete && $_GET['action'] == '') + +if ($user->societe_id == 0 && $_GET['action'] == '') { if ($user->rights->facture->paiement) { - print ''.$langs->trans('Delete').''; + if (! $disable_delete) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } } } diff --git a/htdocs/compta/pre.inc.php b/htdocs/compta/pre.inc.php index 7af97082bf5..6f0fd12d9d1 100644 --- a/htdocs/compta/pre.inc.php +++ b/htdocs/compta/pre.inc.php @@ -18,11 +18,11 @@ */ /** - \file htdocs/compta/pre.inc.php - \ingroup compta - \brief Fichier gestionnaire du menu compta - \version $Id$ -*/ + * \file htdocs/compta/pre.inc.php + * \ingroup compta + * \brief Fichier gestionnaire du menu compta + * \version $Id$ + */ require("../main.inc.php"); @@ -78,14 +78,14 @@ function llxHeader($head = '', $title='', $help_url='') $menu->add(DOL_URL_ROOT."/compta/commande/liste.php?leftmenu=orders&afacturer=1", $langs->trans("MenuOrdersToBill")); } - // Les d�penses + // Les depenses if ($conf->fournisseur->enabled) { $langs->load("suppliers"); $menu->add(DOL_URL_ROOT."/fourn/index.php", $langs->trans("Suppliers")); } - if ($conf->deplacement->enabled && $user->societe_id == 0) + if ($conf->deplacement->enabled) { $langs->load("trips"); $menu->add(DOL_URL_ROOT."/compta/deplacement/", $langs->trans("Trips")); @@ -102,7 +102,7 @@ function llxHeader($head = '', $title='', $help_url='') } - // Vision des recettes-d�penses + // Vision des recettes-depenses if ($conf->banque->enabled && $user->rights->banque->lire) { $langs->load("banks"); diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index f91ff0cbf56..5a694e210e1 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -2040,7 +2040,7 @@ class Facture extends CommonObject * \brief Renvoi le libelle d'un statut donne * \param paye Etat paye * \param statut Id statut - * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Pict + * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * \param alreadypaid Montant deja paye * \param type Type facture * \return string Libelle du statut diff --git a/htdocs/install/mysql/migration/2.7.0-2.8.0.sql b/htdocs/install/mysql/migration/2.7.0-2.8.0.sql index 1c029d56b3b..d7ada466398 100755 --- a/htdocs/install/mysql/migration/2.7.0-2.8.0.sql +++ b/htdocs/install/mysql/migration/2.7.0-2.8.0.sql @@ -14,6 +14,7 @@ ALTER TABLE llx_stock_mouvement ADD COLUMN label varchar(128); ALTER TABLE llx_deplacement ADD COLUMN ref varchar(30) DEFAULT NULL AFTER rowid; ALTER TABLE llx_deplacement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref; +ALTER TABLE llx_deplacement ADD COLUMN note_public text; ALTER TABLE llx_element_element DROP INDEX idx_element_element_idx1; ALTER TABLE llx_element_element DROP INDEX idx_element_element_targetid; diff --git a/htdocs/install/mysql/tables/llx_deplacement.sql b/htdocs/install/mysql/tables/llx_deplacement.sql index ce06c32f6c5..46f43495a76 100644 --- a/htdocs/install/mysql/tables/llx_deplacement.sql +++ b/htdocs/install/mysql/tables/llx_deplacement.sql @@ -32,5 +32,6 @@ create table llx_deplacement type varchar(12) NOT NULL, km real, fk_soc integer, - note text + note text, + note_public text )type=innodb;