From 4a850d7b27557061643c4a99acc822ec4fa4f530 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 6 May 2006 15:15:48 +0000 Subject: [PATCH] =?UTF-8?q?gestion=20des=20contacts=20sur=20les=20commande?= =?UTF-8?q?s=20-=20Merci=20=E0=20MESSIN=20Enguerrand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/commande/apercu.php | 4 + htdocs/commande/commande.class.php | 206 ++++++++ htdocs/commande/contact.php | 476 ++++++++++++++++++ htdocs/commande/fiche.php | 5 + htdocs/commande/info.php | 4 + htdocs/compta/commande/fiche.php | 4 + htdocs/expedition/commande.php | 4 + htdocs/expedition/expedition.class.php | 8 +- htdocs/expedition/fiche.php | 12 +- htdocs/expedition/mods/pdf/README | 2 +- .../mods/pdf/pdf_expedition_merou.modules.php | 391 ++++++++++++++ htdocs/livraison/livraison.class.php | 33 +- mysql/data/data.sql | 5 + mysql/migration/2.0.0-2.1.0.sql | 7 +- 14 files changed, 1140 insertions(+), 21 deletions(-) create mode 100644 htdocs/commande/contact.php create mode 100644 htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php diff --git a/htdocs/commande/apercu.php b/htdocs/commande/apercu.php index 050520ee3bd..58553896ac0 100644 --- a/htdocs/commande/apercu.php +++ b/htdocs/commande/apercu.php @@ -114,6 +114,10 @@ if ($_GET["id"] > 0) { $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id; $head[$h][1] = $langs->trans('Info'); $h++; + + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$commande->id; + $head[$h][1] = $langs->trans('OrderContact'); + $h++; dolibarr_fiche_head($head, $hselected, $langs->trans('Order').': '.$commande->ref); diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 00fd71ea9db..6ef0d0d81fc 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -1328,6 +1328,212 @@ class Commande return -2; } } + + /** + * \brief Liste les valeurs possibles de type de contacts pour les factures + * \param source 'internal' ou 'external' + * \return array Tableau des types de contacts + */ + function liste_type_contact($source) + { + global $langs; + $element='commande'; + $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(); + return null; + } + } + + + /** + * \brief Récupère les lignes de contact de l'objet + * \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; + $element='commande'; + $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='".$element."'"; + 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 Ajoute un contact associé une commande + * \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("Commande::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 + { + $this->error=$this->db->error()." - $sql"; + return -1; + } + } + + + /** + * \brief Supprime une ligne de contact + * \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"; + $sql.= " WHERE rowid =".$rowid; + + if ($this->db->query($sql)) + { + return 1; + } + else + { + return -1; + } + } + + /** + * + * + * + */ + function getIdContact($source,$code) + { + $element='commande'; // Contact sur la facture + $result=array(); + $i=0; + + $sql = "SELECT ec.fk_socpeople"; + $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql.= " WHERE ec.element_id = ".$this->id; + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; + $sql.= " AND tc.element = '".$element."'"; + $sql.= " AND tc.source = '".$source."'"; + $sql.= " AND tc.code = '".$code."'"; + + $resql=$this->db->query($sql); + + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { + $result[$i]=$obj->fk_socpeople; + $i++; + } + } + else + { + $this->error=$this->db->error(); + return null; + } + + return $result; + } + + /** * Supprime la commande diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php new file mode 100644 index 00000000000..f1bd55c8697 --- /dev/null +++ b/htdocs/commande/contact.php @@ -0,0 +1,476 @@ + + * 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."/commande/commande.class.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); + +$langs->load("facture"); +$langs->load("orders"); +$langs->load("sendings"); +$langs->load("companies"); + +$user->getrights('commande'); +if (!$user->rights->commande->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($commande, $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 = $commande->db->query($sql); + if ($resql) + { + $javaScript = "window.location='./contact.php?id=".$commande->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; + print '\n"; + return $firstCompany; + } else + { + dolibarr_print_error($commande->db); + } +} + +/** + * + */ +function select_type_contact($commande, $defValue, $htmlname = 'type', $source) +{ + $lesTypes = $commande->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->commande->creer) +{ + + $result = 0; + $commande = new Commande($db); + $result = $commande->fetch($_GET["id"]); + + if ($result > 0 && $_GET["id"] > 0) + { + $result = $commande->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); + } + + if ($result >= 0) + { + Header("Location: contact.php?id=".$commande->id); + exit; + } else + { + $mesg = '
'.$commande->error.'
'; + } +} +// modification d'un contact. On enregistre le type +if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) +{ + $commande = new Commande($db); + if ($commande->fetch($_GET["id"])) + { + $contact = $commande->detail_contact($_POST["elrowid"]); + $type = $_POST["type"]; + $statut = $contact->statut; + + $result = $commande->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->commande->creer) +{ + $commande = new Commande($db); + if ($commande->fetch($_GET["id"])) + { + $contact = $commande->detail_contact($_GET["ligne"]); + $id_type_contact = $contact->fk_c_type_contact; + $statut = ($contact->statut == 4) ? 5 : 4; + + $result = $commande->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->commande->creer) +{ + $commande = new Commande($db); + $commande->fetch($_GET["id"]); + $result = $commande->delete_contact($_GET["lineid"]); + + if ($result >= 0) + { + Header("Location: contact.php?id=".$commande->id); + exit; + } + else { + dolibarr_print_error($db); + } +} + + +llxHeader('', $langs->trans("Order"), "Commande"); + +$html = new Form($db); + +/* *************************************************************************** */ +/* */ +/* Mode vue et edition */ +/* */ +/* *************************************************************************** */ +if ( isset($mesg)) + print $mesg; +$id = $_GET["id"]; +if ($id > 0) +{ + $langs->trans("OrderCard"); + $commande = New Commande($db); + if ( $commande->fetch($_GET['id'], $user->societe_id) > 0) + { + $soc = new Societe($db, $commande->socidp); + $soc->fetch($commande->socidp); + + $h=0; + + if ($conf->commande->enabled && $user->rights->commande->lire) + { + $head[$h][0] = DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id; + $head[$h][1] = $langs->trans("OrderCard"); + $h++; + } + + if ($conf->expedition->enabled && $user->rights->expedition->lire) + { + $head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id; + $head[$h][1] = $langs->trans("SendingCard"); + $h++; + } + + if ($conf->compta->enabled || $conf->comptaexpert->enabled) + { + $head[$h][0] = DOL_URL_ROOT.'/compta/commande/fiche.php?id='.$commande->id; + $head[$h][1] = $langs->trans("ComptaCard"); + $h++; + } + + if ($conf->use_preview_tabs) + { + $head[$h][0] = DOL_URL_ROOT.'/commande/apercu.php?id='.$commande->id; + $head[$h][1] = $langs->trans("Preview"); + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id; + $head[$h][1] = $langs->trans("Info"); + $h++; + + //Ajout de longlet contacts + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$commande->id; + $head[$h][1] = $langs->trans('OrderContact'); + $hselected = $h; + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("Order").": $commande->ref"); + + /* + * Facture synthese pour rappel + */ + print ''; + + // Reference de la commande + print '"; + + // Customer + if ( is_null($commande->ref_client) ) + $soc = new Societe($db); + $soc->fetch($commande->soc_id); + + print ""; + print ''; + print "
'.$langs->trans("Ref").''; + print $commande->ref; + print "
".$langs->trans("Customer")."'; + print ''.$soc->nom.'
"; + + print ''; + + /* + * Lignes de contacts + */ + echo '
'; + + /* + * Ajouter une ligne de contact + * Non affiché en mode modification de ligne + */ + if ($_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 = $commande->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($commande, '', 'type','internal'); + print '
'; + print $langs->trans("External"); + print ''; + $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$commande->client->id; + $selectedCompany = select_societes_for_newconcat($commande, $selectedCompany, $htmlname = 'newcompany'); + print ''; + $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid'); + print ''; + select_type_contact($commande, '', '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 ($commande->statut >= 0) + print ''; + print img_statut($tab[$i]['status']); + + if ($commande->statut >= 0) + print ''; + print ''; + if ($commande->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/commande/fiche.php b/htdocs/commande/fiche.php index 4a4a20341c8..c5e63fc7457 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -766,6 +766,11 @@ else $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id; $head[$h][1] = $langs->trans('Info'); $h++; + + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$commande->id; + $head[$h][1] = $langs->trans('OrderContact'); + $h++; + dolibarr_fiche_head($head, $hselected, $langs->trans('Order').': '.$commande->ref); diff --git a/htdocs/commande/info.php b/htdocs/commande/info.php index 0a7811fd5c0..7f2e59c6751 100644 --- a/htdocs/commande/info.php +++ b/htdocs/commande/info.php @@ -82,6 +82,10 @@ $h = 0; $head[$h][1] = $langs->trans("Info"); $hselected = $h; $h++; + + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$commande->id; + $head[$h][1] = $langs->trans('OrderContact'); + $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Order").": $commande->ref"); diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index d3e80f27f26..719ca8dbed9 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -121,6 +121,10 @@ if ($_GET["id"] > 0) $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id; $head[$h][1] = $langs->trans("Info"); $h++; + + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$commande->id; + $head[$h][1] = $langs->trans('OrderContact'); + $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Order").": $commande->ref"); diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 07d076f39ba..44eede18c63 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -121,6 +121,10 @@ if ($_GET["id"] > 0) $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id; $head[$h][1] = $langs->trans("Info"); $h++; + + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$commande->id; + $head[$h][1] = $langs->trans('OrderContact'); + $h++; dolibarr_fiche_head($head, $hselected, $langs->trans("Order").": $commande->ref"); diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 439f7ba6cec..aa795ecb04f 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -470,15 +470,17 @@ class Expedition $pdf = new $mod($this->db); - $dir = $conf->expedition->dir_output . "/" .get_exdir($this->id); + //$dir = $conf->expedition->dir_output . "/" .get_exdir($this->id); //test + $dir = $conf->expedition->dir_output . "/" .$this->ref; if (! file_exists($dir)) { create_exdir($dir); } - $file = $dir . $this->id . ".pdf"; - + //$file = $dir . $this->id . ".pdf"; //test + $file = $dir . $this->ref . ".pdf"; + if (file_exists($dir)) { $pdf->generate($this, $file); diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index b922e59f781..3ab0bcb0cfb 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -500,9 +500,16 @@ else /* * Documents générés */ - $filename=sanitize_string($expedition->id); - $filedir=$conf->expedition->dir_output . "/" .get_exdir($expedition->id); + + //mis en commentaire pour test du patch + //$filename=sanitize_string($expedition->id); + //$filedir=$conf->expedition->dir_output . "/" .get_exdir($expedition->id); + + $filename=sanitize_string($expedition->ref); + $filedir=$conf->expedition->dir_output . "/" .$expedition->ref; + $urlsource=$_SERVER["PHP_SELF"]."?id=".$expedition->id; + //$genallowed=$user->rights->expedition->creer; //$delallowed=$user->rights->expedition->supprimer; $genallowed=0; @@ -594,6 +601,7 @@ else if (file_exists($file)) { + print '
'; print "
"; print_titre("Documents"); print ''; diff --git a/htdocs/expedition/mods/pdf/README b/htdocs/expedition/mods/pdf/README index 7d41d6adc5a..d175ea90d65 100644 --- a/htdocs/expedition/mods/pdf/README +++ b/htdocs/expedition/mods/pdf/README @@ -10,11 +10,11 @@ Pris - rouget - dorade +- mérou Disponibles -- mérou - ombrine - mulet - maquereau \ No newline at end of file diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php new file mode 100644 index 00000000000..c2c640bc83c --- /dev/null +++ b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php @@ -0,0 +1,391 @@ + + * Copyright (C) 2005 Laurent Destailleur + * Copyright (C) 2005 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 + * (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. + * or see http://www.gnu.org/ + * + * $Id$ + * $Source$ + */ + +require_once DOL_DOCUMENT_ROOT."/expedition/mods/pdf/ModelePdfExpedition.class.php"; +require_once DOL_DOCUMENT_ROOT."/contact.class.php"; + +Class pdf_expedition_merou extends ModelePdfExpedition{ + + function pdf_expedition_merou($db=0){ + $this->db = $db; + $this->name = "Merou"; + $this->description = "Modele Merou 2xA5 \n + Attention !! Il est nécessaire de creer 4 nouveaux types de contact : \n + |element->commande,source->internal,code->LIVREUR \n + |element->commande,source->external,code->LIVREUR \n + |element->commande,source->external,code->EXPEDITEUR \n + |element->commande,source->external,code->DESTINATAIRE \n +"; + } + + //***************************** + //Creation du Document + //Initialisation des données + //***************************** + function generate(&$objExpe){ + global $user,$langs,$conf; + //Initialisation des langues + $langs->load("main"); + $langs->load("bills"); + $langs->load("products"); + //Generation de la fiche + $this->expe = $objExpe; + $this->expe->fetch_commande(); + //Creation du Client + $this->soc = new Societe($this->db); + $this->soc->fetch($this->expe->commande->soc_id); + //Creation de l expediteur + $this->expediteur = $this->soc; + //Creation du destinataire + $this->destinataire = new Contact($this->db); +// $this->expe->commande->fetch($this->commande->id); +//print_r($this->expe); + $idcontact = $this->expe->commande->getIdContact('external','DESTINATAIRE'); + $this->destinataire->fetch($idcontact[0]); + //Creation du livreur + $idcontact = $this->expe->commande->getIdContact('internal','LIVREUR'); + $this->livreur = new User($this->db,$idcontact[0]); + $this->livreur->fetch(); + + //Verificatio nde la configuration + if ($conf->expedition->dir_output){ + $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","="); + $expref = str_replace($forbidden_chars,"_",$this->expe->ref); + $dir = $conf->expedition->dir_output . "/" . $this->expe->ref . "/" ; + $file = $dir .$this->expe->ref . ".pdf"; + //Si le dossier n existe pas + if (! file_exists($dir)){ + umask(0); + //On tente de le creer + if (! mkdir($dir, 0755)){ + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + //Si le dossier existe + if (file_exists($dir)){ + // Initialisation Bon vierge + $this->FPDF('l','mm','A5'); + $this->Open(); + $this->AddPage(); + //Generation de l entete du fichier + $this->SetTitle($this->expe->ref); + $this->SetSubject($langs->trans("Sending")); + $this->SetCreator("EXPRESSIV Dolibarr ".DOL_VERSION); + $this->SetAuthor($user->fullname); + $this->SetMargins(10, 10, 10); + $this->SetAutoPageBreak(1,0); + //Insertion de l entete + $this->_pagehead($this->expe); + //Initiailisation des coordonnées + $tab_top = 53; + $tab_height = 70; + $this->SetFillColor(240,240,240); + $this->SetTextColor(0,0,0); + $this->SetFont('Arial','', 7); + $this->SetXY (10, $tab_top + 5 ); + $iniY = $this->GetY(); + $curY = $this->GetY(); + $nexY = $this->GetY(); + //Generation du tableau + $this->_tableau($tab_top, $tab_height, $nexY); + //Recuperation des produits de la commande. + $this->expe->commande->fetch_lignes(); + $Produits = $this->expe->commande->lignes; + $nblignes = sizeof($Produits); + for ($i = 0 ; $i < $nblignes ; $i++){ + //Generation du produit + $Prod = new Product($this->db); + $Prod->fetch($Produits[$i]->product_id); + //Creation des cases à cocher + $this->rect(10+3, $curY+1, 3, 3); + $this->rect(20+3, $curY+1, 3, 3); + //Insertion de la reference du produit + $this->SetXY (30, $curY ); + $this->SetFont('Arial','B', 7); + $this->MultiCell(20, 5, $Prod->ref, 0, 'L', 0); + //Insertion du libelle + $this->SetFont('Arial','', 7); + $this->SetXY (50, $curY ); + $this->MultiCell(130, 5, stripslashes($Prod->libelle), 0, 'L', 0); + //Insertion de la quantite + $this->SetFont('Arial','', 7); + $this->SetXY (180, $curY ); + $this->MultiCell(20, 5, $Produits[$i]->qty, 0, 'L', 0); + //Generation de la page 2 + $curY += 4; + $nexY = $curY; + if ($nexY > ($tab_top+$tab_height-10) && $i < $nblignes - 1){ + $this->_tableau($tab_top, $tab_height, $nexY); + $this->_pagefoot(); + $this->AliasNbPages(); + $this->AddPage(); + $nexY = $iniY; + $this->_pagehead($this->expe); + $this->SetTextColor(0,0,0); + $this->SetFont('Arial','', 7); + } + } + //Insertio ndu pied de page + $this->_pagefoot($propale); + $this->AliasNbPages(); + //Cloture du pdf + $this->Close(); + //Ecriture du pdf + $this->Output($file); + return 1; + } + } + } + + //******************************** + // Generation du tableau + //******************************** + function _tableau($tab_top, $tab_height, $nexY){ + global $langs; + $langs->load("main"); + $langs->load("bills"); + $this->SetFont('Arial','B',8); + $this->SetXY(10,$tab_top); + $this->MultiCell(10,5,"LS",0,'C',1); + $this->line(20, $tab_top, 20, $tab_top + $tab_height); + $this->SetXY(20,$tab_top); + $this->MultiCell(10,5,"LR",0,'C',1); + $this->line(30, $tab_top, 30, $tab_top + $tab_height); + $this->SetXY(30,$tab_top); + $this->MultiCell(20,5,$langs->trans("Ref"),0,'C',1); + $this->SetXY(50,$tab_top); + $this->MultiCell(130,5,$langs->trans("Description"),0,'L',1); + $this->SetXY(180,$tab_top); + $this->MultiCell(20,5,$langs->trans("Quantity"),0,'L',1); + $this->Rect(10, $tab_top, 190, $tab_height); + } + + //******************************** + // Generation du Pied de page + //******************************** + function _pagefoot(){ + $this->SetFont('Arial','',8); + $this->SetY(-23); + $this->MultiCell(100, 3, "Déclare avoir reçu les marchandises ci-dessus en bon état,", 0, 'L'); + $this->SetY(-13); + $this->MultiCell(100, 3, "A___________________________________ le ____/_____/__________" , 0, 'C'); + $this->SetXY(120,-23); + $this->MultiCell(100, 3, "Nom et Signature : " , 0, 'C'); + $this->SetXY(-10,-10); + $this->MultiCell(10, 3, $this->PageNo().'/{nb}', 0, 'R'); + } + + + //******************************** + // Generation de l entete + //******************************** + function _pagehead($exp){ + GLOBAL $langs; + $tab4_top = 60; + $tab4_hl = 6; + $tab4_sl = 4; + $ligne = 2; + //*********************LOGO**************************** + if (defined("FAC_PDF_LOGO") && FAC_PDF_LOGO){ + $this->SetXY(10,5); + if (file_exists(FAC_PDF_LOGO)) { + $this->Image(FAC_PDF_LOGO, 10, 5,85.0, 17.0, 'PNG'); + }else { + //Cas Erreur Fichier introuvable + $this->SetTextColor(200,0,0); + $this->SetFont('Arial','B',8); + $this->MultiCell(80, 3, $langs->trans("ErrorLogoFileNotFound",FAC_PDF_LOGO), 0, 'L'); + $this->MultiCell(80, 3, $langs->trans("ErrorGoToModuleSetup"), 0, 'L'); + } + }else if (defined("FAC_PDF_INTITULE")){ + $this->MultiCell(80, 6, FAC_PDF_INTITULE, 0, 'L'); + } + //*********************Entete**************************** + //Nom du Document + $Yoff = 0; + $this->SetXY(60,7); + $this->SetFont('Arial','B',14); + $this->SetTextColor(0,0,0); + $this->MultiCell(0, 8, "BON DE LIVRAISON", '' , 'L'); + //Num Expedition + $Yoff = $Yoff+7; + $Xoff = 115; +// $this->rect($Xoff, $Yoff, 85, 8); + $this->SetXY($Xoff,$Yoff); + $this->SetFont('Arial','',8); + $this->SetTextColor(0,0,0); + $this->MultiCell(0, 8, "Num Bon de Livraison : ".$exp->ref, '' , 'L'); + $this->Code39($Xoff+43, $Yoff+1, $this->expe->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); + //Num Commande + $Yoff = $Yoff+10; +// $this->rect($Xoff, $Yoff, 85, 8); + $this->SetXY($Xoff,$Yoff); + $this->SetFont('Arial','',8); + $this->SetTextColor(0,0,0); + $this->MultiCell(0, 8, "Num Commande : ".$exp->commande->ref, '' , 'L'); + $this->Code39($Xoff+43, $Yoff+1, $exp->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); + //Definition Emplacement du bloc Societe + $blSocX=11; + $blSocY=25; + $blSocW=50; + $blSocX2=$blSocW+$blSocXs; + $this->SetTextColor(0,0,0); + //Adresse Internet + if (defined("FAC_PDF_WWW")){ + $this->SetXY($blSocX,$blSocY); + $this->SetFont('Arial','B',8); + $this->MultiCell($blSocW, 3, FAC_PDF_WWW, '' , 'L'); + } + if (defined("FAC_PDF_ADRESSE")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX,$blSocY+3); + $this->MultiCell($blSocW, 3, FAC_PDF_ADRESSE, '' , 'L'); + } + + if (defined("FAC_PDF_ADRESSE2")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX,$blSocY+6); + $this->MultiCell($blSocW, 3, FAC_PDF_ADRESSE2, '' , 'L'); + } + + if (defined("FAC_PDF_TEL")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX,$blSocY+10); + $this->MultiCell($blSocW, 3, "Tel : " . FAC_PDF_TEL, '' , 'L'); + } + + if (defined("FAC_PDF_MEL")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX,$blSocY+13); + $this->MultiCell(40, 3, "Email : " . FAC_PDF_MEL, '' , 'L'); + } + + if (defined("FAC_PDF_FAX")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX,$blSocY+16); + $this->MultiCell(40, 3, "Fax : " . FAC_PDF_FAX, '' , 'L'); + } + + if (defined("MAIN_INFO_SIRET")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX2,$blSocY+10); + $this->MultiCell($blSocW, 3, "SIRET : " . MAIN_INFO_SIRET, '' , 'L'); + } + + if (defined("MAIN_INFO_APE")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX2,$blSocY+13); + $this->MultiCell($blSocW, 3, "APE : " . MAIN_INFO_APE, '' , 'L'); + } + + if (defined("MAIN_INFO_TVAINTRA")){ + $this->SetFont('Arial','',7); + $this->SetXY($blSocX2,$blSocY+16); + $this->MultiCell($blSocW, 3, "ICOMM : " . MAIN_INFO_TVAINTRA, '' , 'L'); + } + + //Date Expedition + $Yoff = $Yoff+7; + $this->SetXY($blSocX,$blSocY+20); + $this->SetFont('Arial','B',8); + $this->SetTextColor(0,0,0); + $this->MultiCell(50, 8, "Date : " . strftime("%d %b %Y", $exp->date), '' , 'L'); + //Date Expedition + $this->SetXY($blSocX2,$blSocY+20); + $this->SetFont('Arial','B',8); + $this->SetTextColor(0,0,0); + $this->MultiCell(50, 8, "Livreur(s) : ".$this->livreur->fullname, '' , 'L'); + /**********************************/ + //Emplacement Informations Expediteur (Client) + /**********************************/ + $Ydef = $Yoff; + $blExpX=$Xoff-20; + $blW=50; + $Yoff = $Yoff+5; + $Ydef = $Yoff; + $blSocY = 1; + //Titre + $this->SetXY($blExpX,$Yoff-3); + $this->SetFont('Arial','B',7); + $this->MultiCell($blW,3, 'Expéditeur', 0, 'L'); + $this->Rect($blExpX, $Yoff, $blW, 20); + //Nom Client + $this->SetXY($blExpX,$Yoff+$blSocY); + $this->SetFont('Arial','B',7); + $this->MultiCell($blW,3, $this->expediteur->nom, 0, 'C'); + $this->SetFont('Arial','',7); + $blSocY+=3; + //Adresse Client + //Gestion des Retours chariots + $Out=split("\n",$this->expediteur->adresse); + for ($i=0;$iSetXY($blExpX,$Yoff+$blSocY); + $this->MultiCell($blW,5,urldecode($Out[$i]), 0, 'L'); + $blSocY+=3; + } + $this->SetXY($blExpX,$Yoff+$blSocY); + $this->MultiCell($blW,5, $this->expediteur->cp . " " . $this->expediteur->ville, 0, 'L'); + $blSocY+=4; + //Tel Client + $this->SetXY($blExpX,$Yoff+$blSocY); + $this->SetFont('Arial','',7); + $this->MultiCell($blW,3, "Tel : ".$this->expediteur->tel, 0, 'L'); + + /**********************************/ + //Emplacement Informations Destinataire (Contact livraison) + /**********************************/ + $blDestX=$blExpX+55; + $blW=50; + $Yoff = $Ydef; + $blSocY = 1; + //Titre + $this->SetXY($blDestX,$Yoff-3); + $this->SetFont('Arial','B',7); + $this->MultiCell($blW,3, 'Destinataire', 0, 'L'); + $this->Rect($blDestX, $Yoff, $blW, 20); + //Nom Client + $this->SetXY($blDestX,$Yoff+$blSocY); + $this->SetFont('Arial','B',7); + $this->MultiCell($blW,3, $this->destinataire->fullname, 0, 'C'); + $this->SetFont('Arial','',7); + $blSocY+=3; + //Adresse Client + //Gestion des Retours chariots + $Out=split("\n",$this->destinataire->address); + for ($i=0;$iSetXY($blDestX,$Yoff+$blSocY); + $this->MultiCell($blW,5,urldecode($Out[$i]), 0, 'L'); + $blSocY+=3; + } + $this->SetXY($blDestX,$Yoff+$blSocY); + $this->MultiCell($blW,5, $this->destinataire->cp . " " . $this->destinataire->ville, 0, 'L'); + $blSocY+=4; + //Tel Client + $this->SetXY($blDestX,$Yoff+$blSocY); + $this->SetFont('Arial','',7); + $this->MultiCell($blW,3, "Tel : ".$this->destinataire->phone_pro, 0, 'L'); + } +} +?> diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index 78e7d163677..8a90cab904e 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -453,19 +453,19 @@ class Livraison { global $conf; - //EXPEDITION_ADDON_PDF - if (defined("EXPEDITION_ADDON_PDF") && strlen(EXPEDITION_ADDON_PDF) > 0) + //LIVRAISON_ADDON_PDF + if (defined("LIVRAISON_ADDON_PDF") && strlen(LIVRAISON_ADDON_PDF) > 0) { - $module_file_name = DOL_DOCUMENT_ROOT."/expedition/mods/pdf/pdf_expedition_".EXPEDITION_ADDON_PDF.".modules.php"; + $module_file_name = DOL_DOCUMENT_ROOT."/livraison/mods/pdf/pdf_".LIVRAISON_ADDON_PDF.".modules.php"; - $mod = "pdf_expedition_".EXPEDITION_ADDON_PDF; + $mod = "pdf_".LIVRAISON_ADDON_PDF; $this->fetch_commande(); require_once($module_file_name); $pdf = new $mod($this->db); - $dir = $conf->expedition->dir_output . "/" .get_exdir($this->id); + $dir = $conf->livraison->dir_output . "/" .get_exdir($this->id); if (! file_exists($dir)) { @@ -496,13 +496,15 @@ class Livraison { $this->lignes = array(); - $sql = "SELECT c.description, c.qty as qtycom, e.qty as qtyexp"; - $sql .= ", c.fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as e"; + $sql = "SELECT c.label, c.description, c.qty as qtycom, l.qty as qtyliv"; + $sql .= ", c.fk_product, c.price, p.ref"; + $sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as l"; $sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; + $sql .= " , ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE e.fk_expedition = ".$this->id; - $sql .= " AND e.fk_commande_ligne = c.rowid"; + $sql .= " WHERE l.fk_livraison = ".$this->id; + $sql .= " AND l.fk_commande_ligne = c.rowid"; + $sql .= " AND c.fk_product = p.rowid"; $resql = $this->db->query($sql); @@ -512,14 +514,17 @@ class Livraison $i = 0; while ($i < $num) { - $ligne = new ExpeditionLigne(); + $ligne = new LivraisonLigne(); $obj = $this->db->fetch_object($resql); $ligne->product_id = $obj->fk_product; $ligne->qty_commande = $obj->qtycom; - $ligne->qty_expedition = $obj->qtyexp; - $ligne->description = stripslashes($obj->description); + $ligne->qty_livre = $obj->qtyliv; + $ligne->ref = $obj->ref; + $ligne->label = stripslashes($obj->label); + $ligne->description = stripslashes($obj->description); + $ligne->price = $obj->price; $this->lignes[$i] = $ligne; $i++; @@ -533,7 +538,7 @@ class Livraison } -class ExpeditionLigne +class LivraisonLigne { } diff --git a/mysql/data/data.sql b/mysql/data/data.sql index 7a24f5fd27f..34b830469d7 100644 --- a/mysql/data/data.sql +++ b/mysql/data/data.sql @@ -860,3 +860,8 @@ 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 (61, 'facture', 'external', 'SHIPPING', 'Contact client livraison', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (62, 'facture', 'external', 'SERVICE', 'Contact client prestation', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (90, 'commande', 'internal', 'SALESREPSIGN', 'Commercial signataire de la commande', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (91, 'commande', 'internal', 'SALESREPFOLL', 'Commercial suivi de la commande', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (100, 'commande', 'external', 'BILLING', 'Contact client facturation commande', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (101, 'commande', 'external', 'CUSTOMER', 'Contact client suivi commande', 1); + diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index b452ea7984c..0f19b7e71dd 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -222,4 +222,9 @@ create table llx_livraisondet )type=innodb; ALTER TABLE llx_livraison ADD INDEX idx_livraison_fk_soc (fk_soc); -ALTER TABLE llx_livraison ADD CONSTRAINT fk_livraison_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp); \ No newline at end of file +ALTER TABLE llx_livraison ADD CONSTRAINT fk_livraison_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp); + +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (90, 'commande', 'internal', 'SALESREPSIGN', 'Commercial signataire de la commande', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (91, 'commande', 'internal', 'SALESREPFOLL', 'Commercial suivi de la commande', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (100, 'commande', 'external', 'BILLING', 'Contact client facturation commande', 1); +insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (101, 'commande', 'external', 'CUSTOMER', 'Contact client suivi commande', 1); \ No newline at end of file