Fix: move method in common class

This commit is contained in:
Regis Houssin 2012-03-14 11:11:46 +01:00
parent 9821a2d9be
commit 5fbd8e4cee
7 changed files with 66 additions and 106 deletions

View File

@ -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 * Set delivery
* *

View File

@ -112,7 +112,7 @@ else if ($action == 'deleteline' && $user->rights->propale->creer)
else if ($action == 'setaddress' && $user->rights->propale->creer) else if ($action == 'setaddress' && $user->rights->propale->creer)
{ {
$object->fetch($id); $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); if ($result < 0) dol_print_error($db,$object->error);
} }

View File

@ -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 * Set availability
* *

View File

@ -108,7 +108,7 @@ else if ($action == 'deleteline' && $user->rights->commande->creer)
else if ($action == 'setaddress' && $user->rights->commande->creer) else if ($action == 'setaddress' && $user->rights->commande->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->set_adresse_livraison($user,$_POST['fk_address']); $object->setDeliveryAddress($_POST['fk_address']);
} }
/* /*

View File

@ -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 * Set last model used by doc generator
* *

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com> * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -19,8 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// Code identique a /expedition/shipment.php
/** /**
* \file htdocs/expedition/fiche.php * \file htdocs/expedition/fiche.php
* \ingroup expedition * \ingroup expedition
@ -164,7 +162,7 @@ if ($action == 'add')
/* /*
* Build a receiving receipt * 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); $object->fetch($id);
$result = $object->create_delivery($user); $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($id);
$object->fetch_thirdparty(); $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); $object->fetch($id);
$result = $object->delete(); $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); $object->fetch($id);
$result = $object->setStatut(0); $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']; //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')); $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 // Action update description of emailing
if ($action == 'settrackingnumber' || $action == 'settrackingurl' else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
|| $action == 'settrueWeight' || $action == 'settrueWeight'
|| $action == 'settrueWidth' || $action == 'settrueWidth'
|| $action == 'settrueHeight' || $action == 'settrueHeight'
@ -286,7 +284,7 @@ if ($action == 'settrackingnumber' || $action == 'settrackingurl'
/* /*
* Build doc * 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 // 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->fetch($id);
$object->set_billed(); $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 * View
*/ */
@ -1036,16 +1042,26 @@ else
print '</tr>'; print '</tr>';
// Delivery address // Delivery address
if (($origin == 'commande' && $conf->global->COMMANDE_ADD_DELIVERY_ADDRESS) if ($conf->global->COMMANDE_ADD_DELIVERY_ADDRESS || $conf->global->PROPAL_ADD_DELIVERY_ADDRESS)
|| ($origin == 'propal' && $conf->global->PROPAL_ADD_DELIVERY_ADDRESS))
{ {
print '<tr><td>'.$langs->trans('DeliveryAddress').'</td>'; print '<tr><td>';
print '<td colspan="3">'; print '<table class="nobordernopadding" width="100%"><tr><td>';
if (!empty($object->fk_delivery_address)) print $langs->trans('DeliveryAddress');
print '</td>';
if ($action != 'editdelivery_address' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_address&amp;socid='.$object->socid.'&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryAddress'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editdelivery_address')
{ {
$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->deliveryaddress->socid,'none','shipment',$object->id); $formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','shipment',$object->id);
} }
print '</td></tr>'."\n"; else
{
$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','shipment',$object->id);
}
print '</td></tr>';
} }
// Weight // Weight

View File

@ -18,15 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// Code identique a /expedition/fiche.php
/** /**
* \file htdocs/expedition/shipment.php * \file htdocs/expedition/shipment.php
* \ingroup expedition * \ingroup expedition
*/ */
require("../main.inc.php"); 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."/core/class/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php"); require_once(DOL_DOCUMENT_ROOT."/expedition/class/expedition.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.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 = new Commande($db);
$commande->fetch($id); $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) if ($action == 'setmode' && $user->rights->commande->creer)
@ -127,7 +124,6 @@ if ($action == 'setconditions' && $user->rights->commande->creer)
$form = new Form($db); $form = new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$formother = new FormOther($db);
$formproduct = new FormProduct($db); $formproduct = new FormProduct($db);
llxHeader('',$langs->trans('OrderCard'),''); llxHeader('',$langs->trans('OrderCard'),'');
@ -274,29 +270,6 @@ if ($id > 0 || ! empty($ref))
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Delivery address
if ($conf->global->COMMANDE_ADD_DELIVERY_ADDRESS)
{
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('DeliveryAddress');
print '</td>';
if ($action != 'editdelivery_adress' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_adress&amp;socid='.$commande->socid.'&amp;id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '</td></tr>';
}
// Terms of payment // Terms of payment
print '<tr><td height="10">'; print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';