Clean code

This commit is contained in:
Laurent Destailleur 2017-04-30 03:18:49 +02:00
parent b57bf6460b
commit 865c8140d1
11 changed files with 197 additions and 135 deletions

View File

@ -13,7 +13,9 @@ Following changes may create regression for some external modules, but were nece
* The page compta/facture.php was renamed into compta/facture/card.php to match page naming conventions. * The page compta/facture.php was renamed into compta/facture/card.php to match page naming conventions.
* The signature of method ->delete() of class Product and PriceExpression was changed from * The signature of method ->delete() of class Product and PriceExpression was changed from
->delete($id, notrigger) to ->delete(User, notrigger) to match standard dev rules. ->delete($id, notrigger) to ->delete(User, notrigger) to match standard dev rules.
* Removed CommonObject::displayMarginInfos (was deprecated in 3.8). Use same method into
html.formmargin.class.php
* Removed Societe::set_commnucation_level (was deprecated in 4.0). Was not used.
***** ChangeLog for 5.0.1 compared to 5.0.0 ***** ***** ChangeLog for 5.0.1 compared to 5.0.0 *****
FIX: #6503: SQL error in "Last pending payment invoices" FIX: #6503: SQL error in "Last pending payment invoices"

View File

@ -130,12 +130,12 @@ else if ($action == 'deletecontact' && $user->rights->propale->creer)
dol_print_error($db); dol_print_error($db);
} }
} }
/*
else if ($action == 'setaddress' && $user->rights->propale->creer) else if ($action == 'setaddress' && $user->rights->propale->creer)
{ {
$result=$object->setDeliveryAddress($_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

@ -107,13 +107,14 @@ else if ($action == 'deletecontact' && $user->rights->commande->creer)
dol_print_error($db); dol_print_error($db);
} }
} }
/*
else if ($action == 'setaddress' && $user->rights->commande->creer) else if ($action == 'setaddress' && $user->rights->commande->creer)
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->setDeliveryAddress($_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 * View

View File

@ -238,6 +238,7 @@ abstract class CommonObject
/** /**
* @var int Delivery address ID * @var int Delivery address ID
* @deprecated
* @see setDeliveryAddress() * @see setDeliveryAddress()
*/ */
public $fk_delivery_address; public $fk_delivery_address;
@ -1623,6 +1624,7 @@ abstract class CommonObject
/** /**
* Define delivery address * Define delivery address
* @deprecated
* *
* @param int $id Address id * @param int $id Address id
* @return int <0 si ko, >0 si ok * @return int <0 si ko, >0 si ok
@ -3223,51 +3225,14 @@ abstract class CommonObject
/** /**
* Return if a country is inside the EEC (European Economic Community) * Return if a country is inside the EEC (European Economic Community)
* TODO Add a field into dictionary * @deprecated
* *
* @return boolean true = country inside EEC, false = country outside EEC * @return boolean true = country inside EEC, false = country outside EEC
*/ */
function isInEEC() function isInEEC()
{ {
// List of all country codes that are in europe for european vat rules require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
// List found on http://ec.europa.eu/taxation_customs/common/faq/faq_1179_en.htm#9 return isInEEC($this);
$country_code_in_EEC=array(
'AT', // Austria
'BE', // Belgium
'BG', // Bulgaria
'CY', // Cyprus
'CZ', // Czech republic
'DE', // Germany
'DK', // Danemark
'EE', // Estonia
'ES', // Spain
'FI', // Finland
'FR', // France
'GB', // United Kingdom
'GR', // Greece
'HR', // Croatia
'NL', // Holland
'HU', // Hungary
'IE', // Ireland
'IM', // Isle of Man - Included in UK
'IT', // Italy
'LT', // Lithuania
'LU', // Luxembourg
'LV', // Latvia
'MC', // Monaco - Included in France
'MT', // Malta
//'NO', // Norway
'PL', // Poland
'PT', // Portugal
'RO', // Romania
'SE', // Sweden
'SK', // Slovakia
'SI', // Slovenia
'UK', // United Kingdom
//'CH', // Switzerland - No. Swizerland in not in EEC
);
//print "dd".$this->country_code;
return in_array($this->country_code,$country_code_in_EEC);
} }
@ -3754,21 +3719,6 @@ abstract class CommonObject
} }
/**
* Show the array with all margin infos
*
* @param bool $force_price Force price
* @return void
* @deprecated 3.8 Load FormMargin class and make a direct call to displayMarginInfos
*/
function displayMarginInfos($force_price=false)
{
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
$formmargin=new FormMargin($this->db);
$formmargin->displayMarginInfos($this, $force_price);
}
/** /**
* Add resources to the current object : add entry into llx_element_resources * Add resources to the current object : add entry into llx_element_resources
* Need $this->element & $this->id * Need $this->element & $this->id
@ -4711,4 +4661,61 @@ abstract class CommonObject
} }
return $buyPrice; return $buyPrice;
} }
/**
* Create object into database
*
* @param User $user User that creates
* @param bool $notrigger false=launch triggers after, true=disable triggers
*
* @return int <0 if KO, Id of created object if OK
*/
public function createCommon(User $user, $notrigger = false)
{
}
/**
* Load object in memory from the database
*
* @param int $id Id object
* @param string $ref Ref
*
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function fetchCommon($id, $ref = null)
{
}
/**
* Update object into database
*
* @param User $user User that modifies
* @param bool $notrigger false=launch triggers after, true=disable triggers
*
* @return int <0 if KO, >0 if OK
*/
public function updateCommon(User $user, $notrigger = false)
{
}
/**
* Delete object in database
*
* @param User $user User that deletes
* @param bool $notrigger false=launch triggers after, true=disable triggers
*
* @return int <0 if KO, >0 if OK
*/
public function deleteCommon(User $user, $notrigger = false)
{
}
} }

View File

@ -496,6 +496,55 @@ function getFormeJuridiqueLabel($code)
} }
} }
/**
* Return if a country is inside the EEC (European Economic Community)
* TODO Add a field into country dictionary.
*
* @param Object $object Object
* @return boolean true = country inside EEC, false = country outside EEC
*/
function isInEEC($object)
{
// List of all country codes that are in europe for european vat rules
// List found on http://ec.europa.eu/taxation_customs/common/faq/faq_1179_en.htm#9
$country_code_in_EEC=array(
'AT', // Austria
'BE', // Belgium
'BG', // Bulgaria
'CY', // Cyprus
'CZ', // Czech republic
'DE', // Germany
'DK', // Danemark
'EE', // Estonia
'ES', // Spain
'FI', // Finland
'FR', // France
'GB', // United Kingdom
'GR', // Greece
'HR', // Croatia
'NL', // Holland
'HU', // Hungary
'IE', // Ireland
'IM', // Isle of Man - Included in UK
'IT', // Italy
'LT', // Lithuania
'LU', // Luxembourg
'LV', // Latvia
'MC', // Monaco - Included in France
'MT', // Malta
//'NO', // Norway
'PL', // Poland
'PT', // Portugal
'RO', // Romania
'SE', // Sweden
'SK', // Slovakia
'SI', // Slovenia
'UK', // United Kingdom
//'CH', // Switzerland - No. Swizerland in not in EEC
);
//print "dd".$this->country_code;
return in_array($object->country_code, $country_code_in_EEC);
}
/** /**

View File

@ -123,13 +123,13 @@ else if ($action == 'deletecontact' && $user->rights->expedition->creer)
dol_print_error($db); dol_print_error($db);
} }
} }
/*
else if ($action == 'setaddress' && $user->rights->expedition->creer) else if ($action == 'setaddress' && $user->rights->expedition->creer)
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->setDeliveryAddress($_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

@ -113,7 +113,7 @@ if (empty($reshook))
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
/*
if ($action == 'setdeliveryaddress' && $user->rights->commande->creer) if ($action == 'setdeliveryaddress' && $user->rights->commande->creer)
{ {
$object = new Commande($db); $object = new Commande($db);
@ -122,7 +122,7 @@ if (empty($reshook))
if ($result < 0) if ($result < 0)
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
*/
if ($action == 'setmode' && $user->rights->commande->creer) if ($action == 'setmode' && $user->rights->commande->creer)
{ {
$object = new Commande($db); $object = new Commande($db);

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -20,10 +20,9 @@
*/ */
/** /**
* \file dev/skeletons/skeleton_class.class.php * \file modulebuilder/skeletons/skeleton_class.class.php
* \ingroup mymodule othermodule1 othermodule2 * \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
* Put some comments here
*/ */
// Put here all includes required by your class file // Put here all includes required by your class file
@ -34,25 +33,26 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
/** /**
* Class Skeleton_Class * Class Skeleton_Class
* *
* Put here description of your class * Put here description of your class.
*
* @see CommonObject
*/ */
class Skeleton_Class extends CommonObject class Skeleton_Class extends CommonObject
{ {
/** /**
* @var string Id to identify managed objects * @var string Id to identify managed object
*/ */
public $element = 'skeleton'; public $element = 'skeleton';
/** /**
* @var string Name of table without prefix where object is stored * @var string Name of table without prefix where object is stored
*/ */
public $table_element = 'skeleton'; public $table_element = 'skeleton';
/** /**
* @var Skeleton_ClassLine[] Lines * @var array Array with all fields and their property
*/ */
public $lines = array(); public $picto = 'generic';
/**
* @var array Array with all fields and their property
*/
public $fields;
/** /**
* @var mixed Sample property 1 * @var mixed Sample property 1
@ -62,8 +62,21 @@ class Skeleton_Class extends CommonObject
* @var mixed Sample property 2 * @var mixed Sample property 2
*/ */
public $prop2; public $prop2;
//... //...
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $table_element_line = 'skeletondet';
public $class_element_line = 'SkeletonLine';
public $fk_element = 'fk_skeleton';
/**
* @var Skeleton_ClassLine[] Lines
*/
public $lines = array();
/** /**
* Constructor * Constructor
* *
@ -289,10 +302,10 @@ class Skeleton_Class extends CommonObject
*/ */
public function update(User $user, $notrigger = false) public function update(User $user, $notrigger = false)
{ {
$error = 0;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$error = 0;
// Clean parameters // Clean parameters
if (isset($this->prop1)) { if (isset($this->prop1)) {
$this->prop1 = trim($this->prop1); $this->prop1 = trim($this->prop1);

View File

@ -1801,13 +1801,14 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->
/* Barre d'action */ /* Barre d'action */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
if ($action != 'create' && $action != 'edit')
print "\n".'<div class="tabsAction">'."\n";
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{ {
print "\n".'<div class="tabsAction">'."\n";
$parameters=array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer ) || if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer ) ||
($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)) ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer))
{ {
@ -1850,11 +1851,11 @@ if (empty($reshook))
{ {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a></div>'; print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a></div>';
} }
}
print "\n</div>\n";
} }
print "\n</div>\n";
/* /*
* All the "Add to" areas * All the "Add to" areas
*/ */
@ -1974,7 +1975,7 @@ if (! empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action =
* Documents generes * Documents generes
*/ */
if ($action != 'edit' && $action != 'delete') if ($action != 'create' && $action != 'edit' && $action != 'delete')
{ {
print '<div class="fichecenter"><div class="fichehalfleft">'; print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre print '<a name="builddoc"></a>'; // ancre

View File

@ -3326,18 +3326,6 @@ class Societe extends CommonObject
return "Error, mode/status not found"; return "Error, mode/status not found";
} }
/**
* Set commnunication level
*
* @param User $user User making change
* @return int <0 if KO, >0 if OK
* @deprecated Use update function instead
*/
function set_commnucation_level($user)
{
return $this->update($this->id, $user);
}
/** /**
* Set outstanding value * Set outstanding value
* *

View File

@ -107,13 +107,14 @@ else if ($action == 'deletecontact' && $user->rights->societe->creer)
dol_print_error($db); dol_print_error($db);
} }
} }
/*
else if ($action == 'setaddress' && $user->rights->societe->creer) else if ($action == 'setaddress' && $user->rights->societe->creer)
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->setDeliveryAddress($_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 * View