diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index dde40eb84c1..676bbd5bfa5 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1282,34 +1282,6 @@ class Propal extends CommonObject } } - /** - * Define delivery address - * - * @param User $user Object user that modify - * @param int $fk_address Delivery address id - * @return int <0 si ko, >0 si ok - */ - function set_adresse_livraison($user, $fk_address) - { - if ($user->rights->propale->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_adresse_livraison = '".$fk_address."'"; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - if ($this->db->query($sql) ) - { - $this->fk_delivery_address = $fk_address; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Propal::set_adresse_livraison Erreur SQL"); - return -1; - } - } - } - /** * Set delivery * diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 57493f436a9..3123709b0a5 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -112,7 +112,7 @@ else if ($action == 'deleteline' && $user->rights->propale->creer) else if ($action == 'setaddress' && $user->rights->propale->creer) { $object->fetch($id); - $result=$object->set_adresse_livraison($user,$_POST['fk_address']); + $result=$object->setDeliveryAddress($_POST['fk_address']); if ($result < 0) dol_print_error($db,$object->error); } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 08a44f6d24e..d11ab2b1ceb 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1844,34 +1844,6 @@ class Commande extends CommonObject } } - /** - * Set address - * - * @param User $user Object user making change - * @param int $fk_address Adress of delivery - * @return int <0 ig KO, >0 if Ok - */ - function set_adresse_livraison($user, $fk_address) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_adresse_livraison = '".$fk_address."'"; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - if ($this->db->query($sql) ) - { - $this->fk_delivery_address = $fk_address; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Commande::set_adresse_livraison Erreur SQL"); - return -1; - } - } - } - /** * Set availability * diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index fae3c3c1261..e455e6ce54c 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -108,7 +108,7 @@ else if ($action == 'deleteline' && $user->rights->commande->creer) else if ($action == 'setaddress' && $user->rights->commande->creer) { $object->fetch($id); - $object->set_adresse_livraison($user,$_POST['fk_address']); + $object->setDeliveryAddress($_POST['fk_address']); } /* diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8df1964c1de..497607988e8 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -942,6 +942,33 @@ abstract class CommonObject } } + /** + * Define delivery address + * + * @param int $id Address id + * @return int <0 si ko, >0 si ok + */ + function setDeliveryAddress($id) + { + $fieldname = 'fk_adresse_livraison'; + if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; + + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + if ($this->db->query($sql)) + { + $this->fk_delivery_address = $id; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); + return -1; + } + } + /** * Set last model used by doc generator * diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 8ce041038dd..e275178d8ae 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2008 Rodolphe Quiedeville * Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2012 Juanjo Menent * * This program is free software; you can redistribute it and/or modify @@ -19,8 +19,6 @@ * along with this program. If not, see . */ -// Code identique a /expedition/shipment.php - /** * \file htdocs/expedition/fiche.php * \ingroup expedition @@ -164,7 +162,7 @@ if ($action == 'add') /* * Build a receiving receipt */ -if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) +else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer) { $object->fetch($id); $result = $object->create_delivery($user); @@ -179,7 +177,7 @@ if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->righ } } -if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider) +else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider) { $object->fetch($id); $object->fetch_thirdparty(); @@ -208,7 +206,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition } } -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) +else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) { $object->fetch($id); $result = $object->delete(); @@ -223,7 +221,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expeditio } } -if ($action == 'reopen' && $user->rights->expedition->valider) +else if ($action == 'reopen' && $user->rights->expedition->valider) { $object->fetch($id); $result = $object->setStatut(0); @@ -233,7 +231,7 @@ if ($action == 'reopen' && $user->rights->expedition->valider) } } -if ($action == 'setdate_livraison' && $user->rights->expedition->creer) +else if ($action == 'setdate_livraison' && $user->rights->expedition->creer) { //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int')); @@ -247,7 +245,7 @@ if ($action == 'setdate_livraison' && $user->rights->expedition->creer) } // Action update description of emailing -if ($action == 'settrackingnumber' || $action == 'settrackingurl' +else if ($action == 'settrackingnumber' || $action == 'settrackingurl' || $action == 'settrueWeight' || $action == 'settrueWidth' || $action == 'settrueHeight' @@ -286,7 +284,7 @@ if ($action == 'settrackingnumber' || $action == 'settrackingurl' /* * Build doc */ -if ($action == 'builddoc') // En get ou en post +else if ($action == 'builddoc') // En get ou en post { // Sauvegarde le dernier modele choisi pour generer un document @@ -505,12 +503,20 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile' } } -if ($action == 'classifybilled') +else if ($action == 'classifybilled') { $object->fetch($id); $object->set_billed(); } +else if ($action == 'setaddress' && $user->rights->expedition->creer) +{ + $object->fetch($id); + $result=$object->setDeliveryAddress($_POST['fk_address']); + if ($result < 0) dol_print_error($db,$object->error); +} + + /* * View */ @@ -1036,16 +1042,26 @@ else print ''; // Delivery address - if (($origin == 'commande' && $conf->global->COMMANDE_ADD_DELIVERY_ADDRESS) - || ($origin == 'propal' && $conf->global->PROPAL_ADD_DELIVERY_ADDRESS)) + if ($conf->global->COMMANDE_ADD_DELIVERY_ADDRESS || $conf->global->PROPAL_ADD_DELIVERY_ADDRESS) { - print ''.$langs->trans('DeliveryAddress').''; - print ''; - if (!empty($object->fk_delivery_address)) - { - $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->deliveryaddress->socid,'none','shipment',$object->id); - } - print ''."\n"; + print ''; + print ''; + + if ($action != 'editdelivery_address' && $object->brouillon) print ''; + print '
'; + print $langs->trans('DeliveryAddress'); + print 'socid.'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryAddress'),1).'
'; + print ''; + + if ($action == 'editdelivery_address') + { + $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','shipment',$object->id); + } + else + { + $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','shipment',$object->id); + } + print ''; } // Weight diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index a7d9837eccb..5937cfba590 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -18,15 +18,12 @@ * along with this program. If not, see . */ -// Code identique a /expedition/fiche.php - /** * \file htdocs/expedition/shipment.php * \ingroup expedition */ require("../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php"); @@ -100,7 +97,7 @@ if ($action == 'setdeliveryaddress' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($id); - $commande->set_adresse_livraison($user,GETPOST('delivery_address_id','int')); + $commande->setDeliveryAddress(GETPOST('delivery_address_id','int')); } if ($action == 'setmode' && $user->rights->commande->creer) @@ -127,7 +124,6 @@ if ($action == 'setconditions' && $user->rights->commande->creer) $form = new Form($db); $formfile = new FormFile($db); -$formother = new FormOther($db); $formproduct = new FormProduct($db); llxHeader('',$langs->trans('OrderCard'),''); @@ -274,29 +270,6 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - // Delivery address - if ($conf->global->COMMANDE_ADD_DELIVERY_ADDRESS) - { - print ''; - print ''; - - if ($action != 'editdelivery_adress' && $commande->brouillon) print ''; - print '
'; - print $langs->trans('DeliveryAddress'); - print 'socid.'&id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; - print ''; - - if ($action == 'editdelivery_adress') - { - $formother->form_address($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->fk_delivery_address,GETPOST('socid','int'),'delivery_address_id','commande',$commande->id); - } - else - { - $formother->form_address($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->fk_delivery_address,GETPOST('socid','int'),'none','commande',$commande->id); - } - print ''; - } - // Terms of payment print ''; print '
';