Dbut ajout de la gestiondes adresses de livraison

This commit is contained in:
Regis Houssin 2006-04-21 13:00:03 +00:00
parent 374aeba6eb
commit 15a8761ae1
3 changed files with 971 additions and 0 deletions

View File

@ -0,0 +1,518 @@
<?php
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Houssin Régis <regis.houssin@cap-networks.com>
*
* 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/comm/adresse_livraison.class.php
\ingroup societe
\brief Fichier de la classe des adresses de livraison
\version $Revision$
*/
/**
\class Societe
\brief Classe permettant la gestion des adresses de livraison
*/
class Livraison
{
var $db;
var $id;
var $label;
var $socid;
var $nom;
var $adresse;
var $cp;
var $ville;
var $departement_id;
var $pays_id;
var $pays_code;
var $note;
/**
* \brief Constructeur de la classe
* \param DB handler accès base de données
* \param id id societe (0 par defaut)
*/
function Livraison($DB, $id=0)
{
global $conf;
$this->db = $DB;
$this->id = $id;
return 1;
}
/**
* \brief Crée l'adresse de livraison de la société en base
* \param user Objet utilisateur qui demande la création
* \return int 0 si ok, < 0 si erreur
*/
function create($socid, $user='')
{
global $langs,$conf;
// Nettoyage paramètres
$this->nom=trim($this->nom);
$this->label=trim($this->label);
dolibarr_syslog("societe.class.php::create delivery adress ".$this->label);
$this->db->begin();
$result = $this->verify();
if ($result >= 0)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_adresse_livraison (label, fk_societe, nom, datec, fk_user_creat) ";
$sql .= " VALUES ('".addslashes($this->label)."', '".$socid."', '".addslashes($this->nom)."', now(), '".$user->id."')";
$result=$this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_adresse_livraison");
$ret = $this->update($this->id, $socid, $user);
if ($ret >= 0)
{
dolibarr_syslog("Societe::Create delivery adress success id=".$this->id);
$this->db->commit();
return 0;
}
else
{
dolibarr_syslog("Societe::Create delivery adress echec update");
$this->db->rollback();
return -3;
}
}
else
{
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->nom);
}
else
{
dolibarr_syslog("Societe::Create echec insert sql=$sql");
}
$this->db->rollback();
return -2;
}
}
else
{
$this->db->rollback();
dolibarr_syslog("Societe::Create echec verify sql=$sql");
return -1;
}
}
/**
* \brief Verification lors de la modification de l'adresse de livraison
* \return 0 si ok, < 0 en cas d'erreur
*/
function verify()
{
$this->label=trim($this->label);
$this->nom=trim($this->nom);
$result = 0;
if (!$this->nom || !$this->label)
{
$this->error = "Le nom de la société et le label ne peut être vide.\n";
$result = -2;
}
return $result;
}
/**
* \brief Mise a jour des paramètres de l'adresse de livraison
* \param id id adresse de livraison
* \param user Utilisateur qui demande la mise à jour
* \return int <0 si ko, >=0 si ok
*/
function update($idl, $socid, $user='')
{
global $langs;
dolibarr_syslog("Societe::Update");
// Nettoyage des paramètres
$this->fk_societe=$socid;
$this->label=trim($this->label);
$this->nom=trim($this->nom);
$this->adresse=trim($this->adresse);
$this->cp=trim($this->cp);
$this->ville=trim($this->ville);
$this->departement_id=trim($this->departement_id);
$this->pays_id=trim($this->pays_id);
$this->note=trim($this->note);
$result = $this->verify(); // Verifie que nom et label obligatoire
if ($result >= 0)
{
dolibarr_syslog("Societe::Update delivery adress verify ok");
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_adresse_livraison";
$sql.= " SET label = '" . addslashes($this->label) ."'"; // Champ obligatoire
$sql.= ",nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire
$sql.= ",address = '" . addslashes($this->adresse) ."'";
if ($this->cp)
{ $sql .= ",cp = '" . $this->cp ."'"; }
if ($this->ville)
{ $sql .= ",ville = '" . addslashes($this->ville) ."'"; }
$sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'";
$sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'";
$sql.= ",note = '" . addslashes($this->note) ."'";
if ($user) $sql .= ",fk_user_modif = '".$user->id."'";
$sql .= " WHERE fk_societe = '" . $socid ."' AND rowid = '" . $idl ."'";
$resql=$this->db->query($sql);
if ($resql)
{
$result = 1;
}
else
{
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
// Doublon
$this->error = $langs->trans("ErrorDuplicateField");
$result = -1;
}
else
{
$this->error = $langs->trans("Error sql=$sql");
dolibarr_syslog("Societe::Update delivery adress echec sql=$sql");
$result = -2;
}
}
}
return $result;
}
/**
* \brief Charge depuis la base toutes les adresses de livraison d'une société
* \param socid Id de la société à charger en mémoire
* \param user Objet de l'utilisateur
* \return int >0 si ok, <0 si ko
*/
function fetch($socid, $user=0)
{
global $langs, $conf;
$sql = 'SELECT s.idp, s.nom';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql .= ' WHERE s.idp = '.$socid;
$resqlsoc=$this->db->query($sql);
if ($resqlsoc)
{
if ($this->db->num_rows($resqlsoc))
{
$obj = $this->db->fetch_object($resqlsoc);
$this->nom_societe = $obj->nom;
$this->socid = $obj->idp;
$this->id = $obj->idp;
}
$this->lignes = array();
$this->db->free($resqlsoc);
// Adresses de livraison liées à la société
if ($this->socid)
{
$sql = 'SELECT a.rowid as idl, a.label, a.nom, a.address,'.$this->db->pdate('a.datec').' as dc';
$sql .= ','. $this->db->pdate('a.tms').' as date_update, a.fk_societe';
$sql .= ', a.cp, a.ville, a.note, a.fk_departement, a.fk_pays';
$sql .= ', p.code as pays_code, p.libelle as pays';
$sql .= ', d.code_departement as departement_code, d.nom as departement';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_adresse_livraison as a';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON a.fk_pays = p.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON a.fk_departement = d.rowid';
$sql .= ' WHERE a.fk_societe = '.$this->socid;
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$objp = $this->db->fetch_object($resql);
$ligne = new AdresseLivraisonLigne();
$ligne->idl = $objp->idl;
$ligne->date_creation = $objp->dc;
$ligne->date_update = $objp->date_update;
$ligne->label = stripslashes($objp->label);
$ligne->nom = stripslashes($objp->nom);
$ligne->adresse = stripslashes($objp->address);
$ligne->cp = $objp->cp;
$ligne->ville = stripslashes($objp->ville);
$ligne->adresse_full = stripslashes($objp->address) . "\n". $objp->cp . ' '. stripslashes($objp->ville);
$ligne->pays_id = $objp->fk_pays;
$ligne->pays_code = $objp->fk_pays?$objp->pays_code:'';
$ligne->pays = $objp->fk_pays?($langs->trans('Country'.$objp->pays_code)!='Country'.$objp->pays_code?$langs->trans('Country'.$objp->pays_code):$objp->pays):'';
$ligne->departement_id = $objp->fk_departement;
$ligne->departement = $objp->fk_departement?$objp->departement:'';
$ligne->note = $objp->note;
$this->lignes[$i] = $ligne;
$i++;
}
$this->db->free($resql);
return 1;
}
else
{
dolibarr_syslog('Erreur AdresseLivraison::Fetch aucune adresse dde livraison');
return -1;
}
}
else
{
dolibarr_syslog('AdresseLivraison::Societe inconnue');
return -2;
}
}
else
{
dolibarr_syslog('Erreur Societe::Fetch '.$this->db->error());
$this->error=$this->db->error();
}
}
/**
* \brief Charge depuis la base l'objet adresse de livraison
* \param socid Id de l'adresse de livraison à charger en mémoire
* \param user Objet de l'utilisateur
* \return int >0 si ok, <0 si ko
*/
function fetch_adresse($idl, $user=0)
{
global $langs;
global $conf;
$sql = 'SELECT a.rowid, a.label, a.nom, a.address,'.$this->db->pdate('a.datec').' as dc';
$sql .= ','. $this->db->pdate('a.tms').' as date_update';
$sql .= ', a.cp,a.ville, a.note, a.fk_departement, a.fk_pays';
$sql .= ', p.code as pays_code, p.libelle as pays';
$sql .= ', d.code_departement as departement_code, d.nom as departement';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_adresse_livraison as a';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON a.fk_pays = p.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON a.fk_departement = d.rowid';
$sql .= ' WHERE a.rowid = '.$idl;
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->idl = $obj->rowid;
$this->date_update = $obj->date_update;
$this->date_creation = $obj->date_creation;
$this->label = stripslashes($obj->label);
$this->nom = stripslashes($obj->nom);
$this->adresse = stripslashes($obj->address);
$this->cp = $obj->cp;
$this->ville = stripslashes($obj->ville);
$this->adresse_full = stripslashes($obj->address) . "\n". $obj->cp . ' '. stripslashes($obj->ville);
$this->pays_id = $obj->fk_pays;
$this->pays_code = $obj->fk_pays?$obj->pays_code:'';
$this->pays = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):'';
$this->departement_id = $obj->fk_departement;
$this->departement= $obj->fk_departement?$obj->departement:'';
$this->note = $obj->note;
$result = 1;
}
else
{
dolibarr_syslog('Erreur Societe::Fetch aucune adresse de livraison avec id='.$this->id.' - '.$sql);
$this->error='Erreur Societe::Fetch aucune adresse de livraison avec id='.$this->id.' - '.$sql;
$result = -2;
}
$this->db->free($resql);
}
else
{
dolibarr_syslog('Erreur Societe::Fetch echec sql='.$sql);
dolibarr_syslog('Erreur Societe::Fetch '.$this->db->error());
$this->error=$this->db->error();
$result = -3;
}
return $result;
}
/**
* \brief Suppression d'une adresse de livraison
* \param id id de la societe à supprimer
*/
function delete($idl,$socid)
{
dolibarr_syslog("Societe::Delete delivery adress");
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_adresse_livraison";
$sql .= " WHERE rowid=".$idl." AND fk_societe = ".$socid;
$result = $this->db->query($sql);
if (!$result)
{
print $this->db->error() . '<br>' . $sql;
}
}
/**
* \brief Renvoie le nom d'une societe a partir d'un id
* \param id id de la société recherchée
*
*/
function get_nom($id)
{
$sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE idp='$id';";
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows())
{
$obj = $this->db->fetch_object($result);
return $obj->nom;
}
$this->db->free();
}
else {
dolibarr_print_error($this->db);
}
}
/*
* \brief Charge les informations d'ordre info dans l'objet societe
* \param id id de la societe a charger
*/
function info($id)
{
$sql = "SELECT s.idp, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,";
$sql.= " fk_user_creat, fk_user_modif";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE s.idp = ".$id;
$result=$this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->idp;
if ($obj->fk_user_creat) {
$cuser = new User($this->db, $obj->fk_user_creat);
$cuser->fetch();
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif) {
$muser = new User($this->db, $obj->fk_user_modif);
$muser->fetch();
$this->user_modification = $muser;
}
$this->ref = $obj->nom;
$this->date_creation = $obj->datec;
$this->date_modification = $obj->datea;
}
$this->db->free($result);
}
else
{
dolibarr_print_error($this->db);
}
}
}
class AdresseLivraisonLigne
{
var $idl;
var $date_creation;
var $date_update;
var $label;
var $nom;
var $adresse;
var $cp;
var $ville;
var $adresse_full;
var $pays_id;
var $pays_code;
var $pays;
var $departement_id;
var $departement;
var $note;
function AdresseLivraisonLigne()
{
}
}
?>

View File

@ -0,0 +1,442 @@
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis.houssin@cap-networks.com>
*
* 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/comm/adresse_livraison.php
\ingroup societe
\brief Onglet adresse de livraison d'un client
\version $Revision$
*/
require("pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/comm/adresse_livraison.class.php");
$user->getrights('societe');
$user->getrights('commercial');
$langs->load("companies");
$langs->load("commercial");
if (! $user->rights->societe->creer)
{
if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
{
accessforbidden();
}
}
$idl = isset($_GET["idl"])?$_GET["idl"]:'';
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if (! $socid && ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && $_REQUEST["action"] != 'update')) accessforbidden();
// Sécurité accés client
if ($user->societe_id > 0)
{
$_GET["action"] = '';
$_POST["action"] = '';
$socid = $user->societe_id;
}
// Protection restriction commercial
if (!$user->rights->commercial->client->voir && $socid && !$user->societe_id > 0)
{
$sql = "SELECT sc.fk_soc";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE sc.fk_soc = ".$socid." AND sc.fk_user = ".$user->id;
if ( $db->query($sql) )
{
if ( $db->num_rows() == 0) accessforbidden();
}
}
$livraison = new Livraison($db);
/*
* Actions
*/
if ($_POST["action"] == 'add' || $_POST["action"] == 'update')
{
$livraison->socid = $_POST["socid"];
$livraison->label = $_POST["label"];
$livraison->nom = $_POST["nom"];
$livraison->adresse = $_POST["adresse"];
$livraison->cp = $_POST["cp"];
$livraison->ville = $_POST["ville"];
$livraison->pays_id = $_POST["pays_id"];
$livraison->departement_id = $_POST["departement_id"];
$livraison->note = $_POST["note"];
if ($_POST["action"] == 'add')
{
$socid = $_POST["socid"];
$result = $livraison->create($socid, $user);
if ($result >= 0)
{
Header("Location: adresse_livraison.php?socid=".$socid);
exit;
}
else
{
$mesg=$livraison->error;
$_GET["action"]='create';
}
}
if ($_POST["action"] == 'update')
{
$result = $livraison->update($_POST["idl"], $socid, $user);
if ($result >= 0)
{
Header("Location: adresse_livraison.php?socid=".$socid);
exit;
}
else
{
$reload = 0;
$mesg = $livraison->error;
$_GET["action"]= "edit";
}
}
}
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->supprimer)
{
$livraison = new Livraison($db);
$result = $livraison->delete($_GET["idl"], $socid);
if ($result == 0)
{
Header("Location: adresse_livraison.php?socid=".$socid);
exit ;
}
else
{
$reload = 0;
$_GET["action"]='';
}
}
/**
*
*
*/
llxHeader();
$form = new Form($db);
$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
{
if ($user->rights->societe->creer)
{
/*
* Fiche adresse de livraison en mode création
*/
if ($_POST["label"] && $_POST["nom"])
{
$livraison->socid=$_POST["socid"];
$livraison->label=$_POST["label"];
$livraison->nom=$_POST["nom"];
$livraison->adresse=$_POST["adresse"];
$livraison->cp=$_POST["cp"];
$livraison->ville=$_POST["ville"];
$livraison->departement_id=$_POST["departement_id"];
$livraison->note=$_POST["note"];
}
// On positionne pays_id, pays_code et libelle du pays choisi
$livraison->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS;
if ($livraison->pays_id)
{
$sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$livraison->pays_id;
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
}
else
{
dolibarr_print_error($db);
}
$livraison->pays_code=$obj->code;
$livraison->pays=$obj->libelle;
}
print_titre($langs->trans("NewDeliveryAdress"));
print "<br>\n";
if ($livraison->error)
{
print '<div class="error">';
print nl2br($livraison->error);
print '</div>';
}
print '<form action="adresse_livraison.php" method="post" name="formsoc">';
print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans('DeliveryAdressLabel').'</td><td><input type="text" size="30" name="label" value="'.$livraison->label.'"></td></tr>';
print '<tr><td>'.$langs->trans('Name').'</td><td><input type="text" size="30" name="nom" value="'.$livraison->nom.'"></td></tr>';
print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="adresse" cols="40" rows="3" wrap="soft">';
print $livraison->adresse;
print '</textarea></td></tr>';
print '<tr><td>'.$langs->trans('Zip').'</td><td><input size="6" type="text" name="cp" value="'.$livraison->cp.'"';
if ($conf->use_javascript && $conf->global->MAIN_AUTO_FILLTOWNFROMZIP) print ' onChange="autofilltownfromzip_PopupPostalCode(cp.value,ville)"';
print '>';
if ($conf->use_javascript && $conf->global->MAIN_AUTO_FILLTOWNFROMZIP) print ' <input class="button" type="button" name="searchpostalcode" value="'.$langs->trans('FillTownFromZip').'" onclick="autofilltownfromzip_PopupPostalCode(cp.value,ville)">';
print '</td></tr>';
print '<tr><td>'.$langs->trans('Town').'</td><td><input type="text" name="ville" value="'.$livraison->ville.'"></td></tr>';
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
$form->select_pays($livraison->pays_id,'pays_id',$conf->use_javascript?' onChange="autofilltownfromzip_save_refresh_create()"':'');
print '</td></tr>';
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
if ($livraison->pays_id)
{
$form->select_departement($livraison->departement_id,$livraison->pays_code);
}
else
{
print $countrynotdefined;
}
print '</td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3"><textarea name="note" cols="40" rows="6" wrap="soft">';
print $livraison->note;
print '</textarea></td></tr>';
print '<tr><td colspan="4" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans('AddDeliveryAdress').'"></td></tr>'."\n";
print '</table>'."\n";
print '</form>'."\n";
}
}
elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
{
/*
* Fiche societe en mode edition
*/
print_titre($langs->trans("EditDeliveyAdress"));
if ($socid)
{
if ($reload || ! $_POST["nom"])
{
$livraison = new Livraison($db);
$livraison->socid = $socid;
$livraison->fetch_adresse($idl);
}
else
{
$livraison->idl=$_POST["idl"];
$livraison->socid=$_POST["socid"];
$livraison->label=$_POST["label"];
$livraison->nom=$_POST["nom"];
$livraison->adresse=$_POST["adresse"];
$livraison->zip=$_POST["zip"];
$livraison->ville=$_POST["ville"];
$livraison->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS;
$livraison->departement_id=$_POST["departement_id"];
$livraison->note=$_POST["note"];
// On positionne pays_id, pays_code et libelle du pays choisi
if ($livraison->pays_id)
{
$sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$livraison->pays_id;
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
}
else
{
dolibarr_print_error($db);
}
$livraison->pays_code=$obj->code;
$livraison->pays=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle;
}
}
if ($livraison->error)
{
print '<div class="error">';
print $livraison->error;
print '</div>';
}
print '<form action="adresse_livraison.php?socid='.$livraison->socid.'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="socid" value="'.$livraison->socid.'">';
print '<input type="hidden" name="idl" value="'.$livraison->idl.'">';
print '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans('DeliveryAdressLabel').'</td><td colspan="3"><input type="text" size="40" name="label" value="'.$livraison->label.'"></td></tr>';
print '<tr><td>'.$langs->trans('Name').'</td><td colspan="3"><input type="text" size="40" name="nom" value="'.$livraison->nom.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3"><textarea name="adresse" cols="40" rows="3" wrap="soft">';
print $livraison->adresse;
print '</textarea></td></tr>';
print '<tr><td>'.$langs->trans('Zip').'</td><td><input size="6" type="text" name="cp" value="'.$livraison->cp.'"';
if ($conf->use_javascript && $conf->global->MAIN_AUTO_FILLTOWNFROMZIP) print ' onChange="autofilltownfromzip_PopupPostalCode(cp.value,ville)"';
print '>';
if ($conf->use_javascript && $conf->global->MAIN_AUTO_FILLTOWNFROMZIP) print ' <input class="button" type="button" name="searchpostalcode" value="'.$langs->trans('FillTownFromZip').'" onclick="autofilltownfromzip_PopupPostalCode(cp.value,ville)">';
print '</td></tr>';
print '<tr><td>'.$langs->trans('Town').'</td><td><input type="text" name="ville" value="'.$livraison->ville.'"></td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
$form->select_pays($livraison->pays_id,'pays_id',$conf->use_javascript?' onChange="autofilltownfromzip_save_refresh_edit()"':'');
print '</td></tr>';
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
$form->select_departement($livraison->departement_id,$livraison->pays_code);
print '</td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3"><textarea name="note" cols="40" rows="6" wrap="soft">';
print $livraison->note;
print '</textarea></td></tr>';
print '<tr><td align="center" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
print '</table>';
print '</form>';
}
}
else
{
/*
* Fiche société en mode visu
*/
$livraison = new Livraison($db);
$result=$livraison->fetch($socid);
$nblignes = sizeof($livraison->lignes);
if ($result < 0)
{
dolibarr_print_error($db,$livraison->error);
//exit;
}
$head = societe_prepare_head($livraison);
dolibarr_fiche_head($head, 'company', $livraison->nom_societe);
// Confirmation de la suppression de la facture
if ($_GET["action"] == 'delete')
{
$html = new Form($db);
$html->form_confirm("adresse_livraison.php?socid=".$livraison->socid."&amp;idl=".$_GET["idl"],$langs->trans("DeleteDeliveryAdress"),$langs->trans("ConfirmDeleteDeliveryAdress"),"confirm_delete");
print "<br />\n";
}
if ($livraison->error)
{
print '<div class="error">';
print $livraison->error;
print '</div>';
}
for ($i = 0 ; $i < $nblignes ; $i++)
{
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans('DeliveryAdressLabel').'</td><td colspan="3">'.$livraison->lignes[$i]->label.'</td>';
print '<td valign="top" colspan="2" width="50%" rowspan="7">'.$langs->trans('Note').' :<br>'.nl2br($livraison->lignes[$i]->note).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans('Name').'</td><td colspan="3">'.$livraison->lignes[$i]->nom.'</td></tr>';
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($livraison->lignes[$i]->adresse)."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$livraison->lignes[$i]->cp."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$livraison->lignes[$i]->ville."</td></tr>";
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$livraison->lignes[$i]->pays.'</td>';
print '</td></tr>';
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">'.$livraison->lignes[$i]->departement.'</td></tr>';
print '</table>';
/*
*
*/
print '<div class="tabsAction">';
if ($user->rights->societe->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/adresse_livraison.php?socid='.$livraison->socid.'&amp;idl='.$livraison->lignes[$i]->idl.'&amp;action=edit">'.$langs->trans("Edit").'</a>';
}
if ($user->rights->societe->supprimer)
{
print '<a class="butActionDelete" href="'.DOL_URL_ROOT.'/comm/adresse_livraison.php?socid='.$livraison->socid.'&amp;idl='.$livraison->lignes[$i]->idl.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
}
print '</div>';
print '<br>';
}
print '</div>';
if ($_GET["action"] == '')
{
print '<div class="tabsAction">';
if ($user->rights->societe->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/adresse_livraison.php?socid='.$livraison->socid.'&amp;action=create">'.$langs->trans("Add").'</a>';
}
print '</div>';
}
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -326,6 +326,17 @@ if ($socidp > 0)
print '</td><td colspan="3">'.$objsoc->price_level."</td>";
print '</tr>';
}
// adresse de livraison
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("DeliveryAdress");
print '<td><td align="right">';
print '<a href="'.DOL_URL_ROOT.'/comm/adresse_livraison.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
print '</td></tr></table>';
print '</td><td colspan="3"></td>';
print '</tr>';
print "</table>";