Skip to content

Commit

Permalink
Fix: move method in common class
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Mar 14, 2012
1 parent 9821a2d commit 5fbd8e4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 106 deletions.
28 changes: 0 additions & 28 deletions htdocs/comm/propal/class/propal.class.php
Expand Up @@ -1282,34 +1282,6 @@ function set_date_livraison($user, $date_livraison)
}
}

/**
* 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
*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/propal/contact.php
Expand Up @@ -112,7 +112,7 @@
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);
}

Expand Down
28 changes: 0 additions & 28 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -1844,34 +1844,6 @@ function set_date_livraison($user, $date_livraison)
}
}

/**
* 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
*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/commande/contact.php
Expand Up @@ -108,7 +108,7 @@
else if ($action == 'setaddress' && $user->rights->commande->creer)
{
$object->fetch($id);
$object->set_adresse_livraison($user,$_POST['fk_address']);
$object->setDeliveryAddress($_POST['fk_address']);
}

/*
Expand Down
27 changes: 27 additions & 0 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -942,6 +942,33 @@ function setPaymentTerms($id)
}
}

/**
* 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
*
Expand Down
56 changes: 36 additions & 20 deletions htdocs/expedition/fiche.php
Expand Up @@ -2,7 +2,7 @@
/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* 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>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -19,8 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// Code identique a /expedition/shipment.php

/**
* \file htdocs/expedition/fiche.php
* \ingroup expedition
Expand Down Expand Up @@ -164,7 +162,7 @@
/*
* 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);
Expand All @@ -179,7 +177,7 @@
}
}

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();
Expand Down Expand Up @@ -208,7 +206,7 @@
}
}

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();
Expand All @@ -223,7 +221,7 @@
}
}

if ($action == 'reopen' && $user->rights->expedition->valider)
else if ($action == 'reopen' && $user->rights->expedition->valider)
{
$object->fetch($id);
$result = $object->setStatut(0);
Expand All @@ -233,7 +231,7 @@
}
}

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'));
Expand All @@ -247,7 +245,7 @@
}

// Action update description of emailing
if ($action == 'settrackingnumber' || $action == 'settrackingurl'
else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
|| $action == 'settrueWeight'
|| $action == 'settrueWidth'
|| $action == 'settrueHeight'
Expand Down Expand Up @@ -286,7 +284,7 @@
/*
* 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
Expand Down Expand Up @@ -505,12 +503,20 @@
}
}

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
*/
Expand Down Expand Up @@ -1036,16 +1042,26 @@
print '</tr>';

// 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 '<tr><td>'.$langs->trans('DeliveryAddress').'</td>';
print '<td colspan="3">';
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 '</td></tr>'."\n";
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
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->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 '</td></tr>';
}

// Weight
Expand Down
29 changes: 1 addition & 28 deletions htdocs/expedition/shipment.php
Expand Up @@ -18,15 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// 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");
Expand Down Expand Up @@ -100,7 +97,7 @@
{
$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)
Expand All @@ -127,7 +124,6 @@

$form = new Form($db);
$formfile = new FormFile($db);
$formother = new FormOther($db);
$formproduct = new FormProduct($db);

llxHeader('',$langs->trans('OrderCard'),'');
Expand Down Expand Up @@ -274,29 +270,6 @@
print '</td>';
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
print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>';
Expand Down

0 comments on commit 5fbd8e4

Please sign in to comment.