From d0721e856731c8e3fb05217fc1e0b8d0e94bb7b6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 30 Nov 2005 17:37:01 +0000 Subject: [PATCH] Ajout patch de la tache 4984 - merci Patrick --- htdocs/compta/facture.php | 8 +- htdocs/compta/facture/apercu.php | 4 + htdocs/compta/facture/contact.php | 438 ++++++++++++++++++++++++++++++ htdocs/compta/facture/info.php | 6 +- htdocs/compta/facture/note.php | 5 + htdocs/compta/facture/pre.inc.php | 40 +++ htdocs/compta/pre.inc.php | 39 +++ htdocs/facture.class.php | 226 ++++++++++++++- mysql/data/data.sql | 4 + mysql/migration/1.1.0-2.0.0.sql | 4 + pgsql/data/data.sql | 86 +++++- 11 files changed, 854 insertions(+), 6 deletions(-) create mode 100644 htdocs/compta/facture/contact.php diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index d66ebb2fa5b..0ae12c81046 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -551,9 +551,6 @@ if ($_GET['action'] == 'pdf') facture_pdf_create($db, $_GET['facid']); } - - - /********************************************************************* * * Fonctions internes @@ -1101,6 +1098,7 @@ else $author->id = $fac->user_author; $author->fetch(); +/* // modification tache 4984, je laisse en commentaire pour test $h = 0; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; @@ -1130,7 +1128,11 @@ else $h++; dolibarr_fiche_head($head, $hselected, $langs->trans('Bill').' : '.$fac->ref); +*/ + $head = facture_prepare_head($fac); + + dolibarr_fiche_head($head, 0, $langs->trans('Bill').' : '.$fac->ref); /* * Confirmation de la suppression de la facture diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 8e6db6bb2d5..a51cdfb24d2 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -69,6 +69,7 @@ if ($_GET["facid"] > 0) $author->id = $fac->user_author; $author->fetch(); +/* //modif tache 4984 laissé en commentaire pour test $h = 0; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; @@ -96,7 +97,10 @@ if ($_GET["facid"] > 0) $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Info"); $h++; +*/ + $head = facture_prepare_head($fac); + $hselected = $conf->use_preview_tabs ? 2 : false; dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php new file mode 100644 index 00000000000..84053b805dd --- /dev/null +++ b/htdocs/compta/facture/contact.php @@ -0,0 +1,438 @@ + + * Copyright (C) 2005 Destailleur Laurent + * + * 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. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/compta/contact.php + \ingroup facture + \brief Onglet de gestion des contacts des factures + \version $Revision$ +*/ + +require ("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); + +$langs->load("facture"); +// $langs->load("orders"); +$langs->load("companies"); + +$user->getrights('facture'); + +if (!$user->rights->facture->lire) + accessforbidden(); + +// les methodes locales +/** + * \brief Retourne la liste déroulante des sociétés + * \param selected Societe présélectionnée + * \param htmlname Nom champ formulaire + */ +function select_societes_for_newconcat($facture, $selected = '', $htmlname = 'newcompany') +{ + // On recherche les societes + $sql = "SELECT s.idp, s.nom FROM"; + $sql .= " ".MAIN_DB_PREFIX."societe as s"; +// if ($filter) $sql .= " WHERE $filter"; + $sql .= " ORDER BY nom ASC"; + + $resql = $facture->db->query($sql); + if ($resql) + { + $javaScript = "window.location='./contact.php?facid=".$facture->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; + print '\n"; + return $firstCompany; + } else + { + dolibarr_print_error($facture->db); + } +} + +/** + * + */ +function select_type_contact($facture, $defValue, $htmlname = 'type', $source) +{ + $lesTypes = $facture->liste_type_contact($source); + print '\n"; +} + + +// Sécurité accés client +if ($user->societe_id > 0) +{ + $action = ''; + $socidp = $user->societe_id; +} + +/* + * Ajout d'un nouveau contact + */ + +if ($_POST["action"] == 'addcontact' && $user->rights->facture->creer) +{ + + $result = 0; + $facture = new Facture($db); + $result = $facture->fetch($_GET["facid"]); + + if ($result > 0 && $_GET["facid"] > 0) + { + $result = $facture->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); + } + + if ($result >= 0) + { + Header("Location: contact.php?facid=".$facture->id); + exit; + } else + { + $mesg = '
'.$facture->error.'
'; + } +} +// modification d'un contact. On enregistre le type +if ($_POST["action"] == 'updateligne' && $user->rights->facture->creer) +{ + $facture = new Facture($db); + if ($facture->fetch($_GET["facid"])) + { + $contact = $facture->detail_contact($_POST["elrowid"]); + $type = $_POST["type"]; + $statut = $contact->statut; + + $result = $facture->update_contact($_POST["elrowid"], $statut, $type); + if ($result >= 0) + { + $db->commit(); + } else + { + dolibarr_print_error($db, "result=$result"); + $db->rollback(); + } + } else + { + dolibarr_print_error($db); + } +} + +// bascule du statut d'un contact +if ($_GET["action"] == 'swapstatut' && $user->rights->facture->creer) +{ + $facture = new Facture($db); + if ($facture->fetch($_GET["facid"])) + { + $contact = $facture->detail_contact($_GET["ligne"]); + $id_type_contact = $contact->fk_c_type_contact; + $statut = ($contact->statut == 4) ? 5 : 4; + + $result = $facture->update_contact($_GET["ligne"], $statut, $id_type_contact); + if ($result >= 0) + { + $db->commit(); + } else + { + dolibarr_print_error($db, "result=$result"); + $db->rollback(); + } + } else + { + dolibarr_print_error($db); + } +} + +// Efface un contact +if ($_GET["action"] == 'deleteline' && $user->rights->facture->creer) +{ + $facture = new Facture($db); + $facture->fetch($_GET["facid"]); + $result = $facture->delete_contact($_GET["lineid"]); + + if ($result >= 0) + { + Header("Location: contact.php?facid=".$facture->id); + exit; + } + else { + dolibarr_print_error($db); + } +} + + +llxHeader('', $langs->trans("Bill"), "Facture"); + +$html = new Form($db); + +/* *************************************************************************** */ +/* */ +/* Mode vue et edition */ +/* */ +/* *************************************************************************** */ +if ( isset($mesg)) + print $mesg; +$id = $_GET["facid"]; +if ($id > 0) +{ + $facture = New Facture($db); + if ( $facture->fetch($_GET['facid'], $user->societe_id) > 0) + { + $soc = new Societe($db, $facture->socidp); + $soc->fetch($facture->socidp); + + $head = facture_prepare_head($facture); + + dolibarr_fiche_head($head, 1, $langs->trans('Bill').' : '.$facture->ref); + + /* + * Facture synthese pour rappel + */ + print ''; + + // Reference du facture + print '"; + + // Customer + if ( is_null($facture->client) ) + $facture->fetch_client(); + + print ""; + print ''; + print "
'.$langs->trans("Ref").''; + print $facture->ref; + print "
".$langs->trans("Customer")."'; + print ''.$facture->client->nom.'
"; + + print ''; + + /* + * Lignes de contacts + */ + echo '
'; + + /* + * Ajouter une ligne de contact + * Non affiché en mode modification de ligne + * ou si facture validée. + */ + if ($facture->statut <= 0 && $_GET["action"] != 'editline' && $user->rights->facture->creer) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var = false; + + print ''; + print ''; + print ''; + print ''; + + // Ligne ajout pour contact interne + print ""; + + print ''; + + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + print ''; + print ''; + print ''; + + // Ligne ajout pour contact externe + $var=!$var; + print ""; + + print ''; + + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ""; + + } + + print ''; + + // Liste des contacts liés + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $societe = new Societe($db); + $var = true; + + foreach(array('internal','external') as $source) + { + $tab = $facture->liste_contact(-1,$source); + $num=sizeof($tab); + + $i = 0; + while ($i < $num) + { + $var = !$var; + + print ''; + + // Source + print ''; + + // Societe + print ''; + + // Contact + print ''; + + // Type de contact + print ''; + + // Statut + print ''; + + // Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé) + print ''; + + print "\n"; + + $i ++; + } + $db->free($result); + } + print "
'.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").' 
'; + print $langs->trans("Internal"); + print ''; + print $conf->global->MAIN_INFO_SOCIETE_NOM; + print ''; + $html->select_users($user->id,'contactid'); + print ''; + select_type_contact($facture, '', 'type','internal'); + print '
'; + print $langs->trans("External"); + print ''; + $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$facture->client->id; + $selectedCompany = select_societes_for_newconcat($facture, $selectedCompany, $htmlname = 'newcompany'); + print ''; + $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid'); + print ''; + select_type_contact($facture, '', 'type','external'); + print '
 
'.$langs->trans("Source").''.$langs->trans("Company").''.$langs->trans("Contacts").''.$langs->trans("ContactType").''.$langs->trans("Status").' 
'; + if ($tab[$i]['source']=='internal') print $langs->trans("Internal"); + if ($tab[$i]['source']=='external') print $langs->trans("External"); + print ''; + if ($tab[$i]['socid'] > 0) + { + print ''; + print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($tab[$i]['socid']); + print ''; + } + if ($tab[$i]['socid'] < 0) + { + print $conf->global->MAIN_INFO_SOCIETE_NOM; + } + if (! $tab[$i]['socid']) + { + print ' '; + } + print ''; + if ($tab[$i]['source']=='internal') + { + print ''; + print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].''; + } + if ($tab[$i]['source']=='external') + { + print ''; + print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].''; + } + print ''.$tab[$i]['libelle'].''; + // Activation desativation du contact + if ($facture->statut >= 0) + print ''; + print img_statut($tab[$i]['status']); + + if ($facture->statut >= 0) + print ''; + print ''; + if ($facture->statut == 0 && $user->rights->facture->creer) + { + print ' '; + print ''; + print img_delete(); + print ''; + } + print '
"; + } + else + { + // Contrat non trouvé + print "Contrat inexistant ou accés refusé"; + } +} + +$db->close(); + +llxFooter('$Date$'); +?> \ No newline at end of file diff --git a/htdocs/compta/facture/info.php b/htdocs/compta/facture/info.php index dc25988d225..a8839e36c9d 100644 --- a/htdocs/compta/facture/info.php +++ b/htdocs/compta/facture/info.php @@ -45,6 +45,7 @@ $fac->info($_GET["facid"]); $soc = new Societe($db, $fac->socidp); $soc->fetch($fac->socidp); +/* //laissé pour test tache 4984 $h = 0; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; @@ -73,8 +74,11 @@ $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Info"); $hselected = $h; $h++; +*/ - +$head = facture_prepare_head($fac); +$hselected = $conf->use_preview_tabs ? + (($fac->mode_reglement_code == 'PRE') ? 5: 4): 3; dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php index fd18da3619d..3dc2803cc74 100644 --- a/htdocs/compta/facture/note.php +++ b/htdocs/compta/facture/note.php @@ -75,6 +75,7 @@ if ($_GET["facid"]) $soc = new Societe($db, $fac->socidp); $soc->fetch($fac->socidp); +/* //laissé en commentaire pour test tache 4984 $h=0; $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; @@ -102,7 +103,11 @@ if ($_GET["facid"]) $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; $head[$h][1] = $langs->trans("Info"); $h++; +*/ + $head = facture_prepare_head($fac); + $hselected = $conf->use_preview_tabs ? + (($fac->mode_reglement_code == 'PRE') ? 4: 3): 2; dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref"); diff --git a/htdocs/compta/facture/pre.inc.php b/htdocs/compta/facture/pre.inc.php index 093a19c49e9..c3aa32f82b2 100644 --- a/htdocs/compta/facture/pre.inc.php +++ b/htdocs/compta/facture/pre.inc.php @@ -56,4 +56,44 @@ function llxHeader($head = "", $title="", $help_url='') { left_menu($menu->liste, $help_url); } +function facture_prepare_head($fac) +{ + global $langs, $conf; + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('CardBill'); + $hselected = $h; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Contact'); + $h++; + + if ($conf->use_preview_tabs) + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Preview'); + $h++; + } + + if ($fac->mode_reglement_code == 'PRE') + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('StandingOrders'); + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Note'); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Info'); + $h++; + + return $head; +} + + ?> diff --git a/htdocs/compta/pre.inc.php b/htdocs/compta/pre.inc.php index e429b089308..e5f21082fcb 100644 --- a/htdocs/compta/pre.inc.php +++ b/htdocs/compta/pre.inc.php @@ -135,4 +135,43 @@ function llxHeader($head = "", $title="", $help_url='') left_menu($menu->liste, $help_url); } +function facture_prepare_head($fac) +{ + global $langs, $conf; + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('CardBill'); + $hselected = $h; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Contact'); + $h++; + + if ($conf->use_preview_tabs) + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Preview'); + $h++; + } + + if ($fac->mode_reglement_code == 'PRE') + { + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('StandingOrders'); + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Note'); + $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$fac->id; + $head[$h][1] = $langs->trans('Info'); + $h++; + + return $head; +} + ?> diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 11fa97f7584..fd1b37c8600 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -92,6 +92,7 @@ class Facture */ function create($user) { + global $langs,$conf; $this->db->begin(); /* On positionne en mode brouillon la facture */ @@ -575,6 +576,8 @@ class Facture */ function delete($rowid) { + global $user,$langs,$conf; + $this->db->begin(); $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$rowid; @@ -1760,6 +1763,227 @@ class Facture } } + + /** + * \brief Ajoute un contact associé une facture + * \param fk_socpeople Id du contact a ajouter. + * \param type_contact Type de contact + * \param source extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user) + * \return int <0 si erreur, >0 si ok + */ + function add_contact($fk_socpeople, $type_contact, $source='extern') + { + dolibarr_syslog("Facture::add_contact $fk_socpeople, $type_contact, $source"); + + if ($fk_socpeople <= 0) return -1; + + // Verifie type_contact + if (! $type_contact || ! is_numeric($type_contact)) + { + $this->error="Valeur pour type_contact incorrect"; + return -3; + } + + $datecreate = time(); + + // Insertion dans la base + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; + $sql.= $this->db->idate($datecreate); + $sql.= ", 4, '". $type_contact . "' "; + $sql.= ");"; + + // Retour + if ( $this->db->query($sql) ) + { + return 1; + } + else + { +// dolibarr_print_error($this->db); + $this->error=$this->db->error()." - $sql"; + return -1; + } + } + + /** + * + * \brief Mise a jour du contact associé une facture + * \param rowid La reference du lien facture-contact + * \param statut Le nouveau statut + * \param type_contact_id Description du type de contact + * \return int <0 si erreur, >0 si ok + */ + function update_contact($rowid, $statut, $type_contact_id) + { + // Insertion dans la base + $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set "; + $sql.= " statut = $statut ,"; + $sql.= " fk_c_type_contact = '".$type_contact_id ."'"; + $sql.= " where rowid = $rowid ;"; + // Retour + if ( $this->db->query($sql) ) + { + return 0; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + /** + * \brief Supprime une ligne de contact de contrat + * \param rowid La reference du contact + * \return statur >0 si ok, <0 si ko + */ + function delete_contact($rowid) + { + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact WHERE rowid =".$rowid; + if ($this->db->query($sql)) + { + return 1; + } + else + { + return -1; + } + } + + /** + * \brief Récupère les lignes de contact du contrat + * \param statut Statut des lignes detail à récupérer + * \param source Source du contact external (llx_socpeople) ou internal (llx_user) + * \return array Tableau des rowid des contacts + */ + function liste_contact($statut=-1,$source='external') + { + global $langs; + + $tab=array(); + + $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,"; + if ($source == 'internal') $sql.=" '-1' as socid,"; + if ($source == 'external') $sql.=" t.fk_soc as socid,"; + if ($source == 'internal') $sql.=" t.name as nom,"; + if ($source == 'external') $sql.=" t.name as nom,"; + $sql.= "tc.source, tc.element, tc.code, tc.libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,"; + if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,"; + if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,"; + $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; + $sql.= " WHERE element_id =".$this->id; + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; + $sql.= " AND tc.element='facture'"; + if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; + if ($source == 'external') $sql.= " AND tc.source = 'external'"; + $sql.= " AND tc.active=1"; + if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid"; + if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp"; + if ($statut >= 0) $sql.= " AND statut = '$statut'"; + $sql.=" ORDER BY t.name ASC"; + + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); + $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom, + 'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut); + $i++; + } + return $tab; + } + else + { + $this->error=$this->db->error(); + dolibarr_print_error($this->db); + return -1; + } + } + + /** + * \brief Le détail d'un contact + * \param rowid L'identifiant du contact + * \return object L'objet construit par DoliDb.fetch_object + */ + function detail_contact($rowid) + { + $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; + $sql.= " tc.code, tc.libelle, s.fk_soc"; + $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, "; + $sql.= " ".MAIN_DB_PREFIX."socpeople as s"; + $sql.= " WHERE ec.rowid =".$rowid; + $sql.= " AND ec.fk_socpeople=s.idp"; + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; + $sql.= " AND tc.element = 'facture'"; + + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + return $obj; + } + else + { + $this->error=$this->db->error(); + dolibarr_print_error($this->db); + return null; + } + } + + /** + * \brief La liste des valeurs possibles de type de contacts + * \param source internal ou external + * \return array La liste des natures + */ + function liste_type_contact($source) + { + global $langs; + + $element='facture'; + + $tab = array(); + + $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql.= " WHERE element='".$element."'"; + $sql.= " AND source='".$source."'"; + $sql.= " ORDER by tc.code"; + + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + $transkey="TypeContact_".$element."_".$source."_".$obj->code; + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); + $tab[$obj->rowid]=$libelle_type; + $i++; + } + return $tab; + } + else + { + $this->error=$this->db->error(); +// dolibarr_print_error($this->db); + return null; + } + } + } @@ -1809,7 +2033,7 @@ class FactureLigne $this->produit_id = $objp->fk_product; $this->date_start = $objp->date_start; $this->date_end = $objp->date_end; - $i++; +// $i++; //modification suite à la tache 4984 $this->db->free($result); } else diff --git a/mysql/data/data.sql b/mysql/data/data.sql index 6c6c544e36f..7de5a4850cf 100644 --- a/mysql/data/data.sql +++ b/mysql/data/data.sql @@ -812,3 +812,7 @@ insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) v insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (80, 'projet', 'internal', 'PROJECTLEADER', 'Chef de Projet', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (81, 'projet', 'external', 'PROJECTLEADER', 'Chef de Projet', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (50, 'facture', 'internal', 'SALESREPFOLL', 'Commercial suivi du paiement', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (60, 'facture', 'external', 'BILLING', 'Contact client facturation', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (61, 'facture', 'external', 'CUSTOMER', 'Contact client livraison/préstation', 1); + diff --git a/mysql/migration/1.1.0-2.0.0.sql b/mysql/migration/1.1.0-2.0.0.sql index 8e10443de8f..7b5bdac025f 100644 --- a/mysql/migration/1.1.0-2.0.0.sql +++ b/mysql/migration/1.1.0-2.0.0.sql @@ -1928,6 +1928,10 @@ insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) v insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (80, 'projet', 'internal', 'PROJECTLEADER', 'Chef de Projet', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (81, 'projet', 'external', 'PROJECTLEADER', 'Chef de Projet', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (50, 'facture', 'internal', 'SALESREPFOLL', 'Commercial suivi du paiement', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (60, 'facture', 'external', 'BILLING', 'Contact client facturation', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (61, 'facture', 'external', 'CUSTOMER', 'Contact client livraison/préstation', 1); + alter table llx_commande add ref_client varchar(30) after ref; alter table llx_facture add ref_client varchar(30) after facnumber; diff --git a/pgsql/data/data.sql b/pgsql/data/data.sql index dc8b1f0a71a..b3baa5f7eb7 100644 --- a/pgsql/data/data.sql +++ b/pgsql/data/data.sql @@ -690,4 +690,88 @@ insert into llx_c_currencies ( code, code_iso, active, label ) values ( 'IN', 'I insert into llx_c_currencies ( code, code_iso, active, label ) values ( 'LT', 'LTL', 1, 'Litas'); insert into llx_c_currencies ( code, code_iso, active, label ) values ( 'RU', 'SUR', 1, 'Rouble'); insert into llx_c_currencies ( code, code_iso, active, label ) values ( 'FH', 'HUF', 1, 'Forint hongrois'); -insert into llx_c_currencies ( code, code_iso, active, label ) values ( 'LK', 'LKR', 1, 'Roupie sri lanka'); +insert into llx_c_currencies ( code, code_iso, active, label ) values ( 'LK', 'LKR', 1, 'Roupie sri lanka'); + +-- +-- Taux TVA +-- Source des taux: http://fr.wikipedia.org/wiki/Taxe_sur_la_valeur_ajout%C3%A9e +-- + +delete from llx_c_tva; + +-- ALLEMAGNE (id 5) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 51, 5, '16','0','VAT Rate 16',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 52, 5, '7','0','VAT Rate 7',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 53, 5, '0','0','VAT Rate 0',1); + +-- BELGIQUE (id 2) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 21, 2, '21','0','VAT Rate 21',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 22, 2, '6','0','VAT Rate 6',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 23, 2, '0','0','VAT Rate 0 ou non applicable',1); + +-- CANADA (id 14) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (141,14, '7','0','VAT Rate 7',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (142,14, '0','0','VAT Rate 0',1); + +-- ESPAGNE (id 4) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 41, 4, '16','0','VAT Rate 16',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 42, 4, '7','0','VAT Rate 7',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 43, 4, '4','0','VAT Rate 4',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 44, 4, '0','0','VAT Rate 0',1); + +-- ITALY (id 3) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 31, 3, '20','0','VAT Rate 20',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 32, 3, '10','0','VAT Rate 10',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 33, 3, '4','0','VAT Rate 4',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 34, 3, '0','0','VAT Rate 0',1); + +-- FRANCE (id 1) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 11, 1,'19.6','0','VAT Rate 19.6 (France hors DOM-TOM)',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 12, 1, '8.5','0','VAT Rate 8.5 (DOM sauf Guyane et Saint-Martin)',0); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 13, 1, '8.5','1','VAT Rate 8.5 (DOM sauf Guyane et Saint-Martin), non perçu par le vendeur mais récupérable par l\'acheteur',0); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 14, 1, '5.5','0','VAT Rate 5.5 (France hors DOM-TOM)',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 15, 1, '0','0','VAT Rate 0 ou non applicable (France, TOM)',1); + +-- PAYS-BAS (id 17) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (171,17, '19','0','VAT Rate 19',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (172,17, '6','0','VAT Rate 6',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (173,17, '0','0','VAT Rate 0',1); + +-- PORTUGAL (id 26) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (261,26, '17','0','VAT Rate 17',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (262,26, '12','0','VAT Rate 12',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (263,26, '0','0','VAT Rate 0',1); + +-- ROYAUME UNI (id 7) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 71, 7,'17.5','0','VAT Rate 17.5',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 72, 7, '5','0','VAT Rate 5',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 73, 7, '0','0','VAT Rate 0',1); + +-- SUISSE (id 6) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 61, 6, '7.6','0','VAT Rate 7.6',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 62, 6, '3.6','0','VAT Rate 3.6',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 63, 6, '2.4','0','VAT Rate 2.4',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 64, 6, '0','0','VAT Rate 0',1); + + + +-- +-- Les types de contact d'un element +-- +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (10, 'contrat', 'internal', 'SALESREPSIGN', 'Commercial signataire du contrat', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (11, 'contrat', 'internal', 'SALESREPFOLL', 'Commercial suivi du contrat', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (20, 'contrat', 'external', 'BILLING', 'Contact client facturation contrat', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (21, 'contrat', 'external', 'CUSTOMER', 'Contact client suivi contrat', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (22, 'contrat', 'external', 'SALESREPSIGN', 'Contact client signataire contrat', 1); + +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (30, 'propal', 'internal', 'SALESREPSIGN', 'Commercial signataire de la propale', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (31, 'propal', 'internal', 'SALESREPFOLL', 'Commercial suivi de la propale', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (40, 'propal', 'external', 'BILLING', 'Contact client facturation propale', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (41, 'propal', 'external', 'CUSTOMER', 'Contact client suivi propale', 1); + +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (80, 'projet', 'internal', 'PROJECTLEADER', 'Chef de Projet', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (81, 'projet', 'external', 'PROJECTLEADER', 'Chef de Projet', 1); + +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (50, 'facture', 'internal', 'SALESREPFOLL', 'Commercial suivi du paiement', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (60, 'facture', 'external', 'BILLING', 'Contact client facturation', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (61, 'facture', 'external', 'CUSTOMER', 'Contact client livraison/préstation', 1);