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 signature of method ->delete() of class Product and PriceExpression was changed from
->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 *****
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);
}
}
/*
else if ($action == 'setaddress' && $user->rights->propale->creer)
{
$result=$object->setDeliveryAddress($_POST['fk_address']);
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);
}
}
/*
else if ($action == 'setaddress' && $user->rights->commande->creer)
{
$object->fetch($id);
$result=$object->setDeliveryAddress($_POST['fk_address']);
if ($result < 0) dol_print_error($db,$object->error);
}
}*/
/*
* View

View File

@ -238,6 +238,7 @@ abstract class CommonObject
/**
* @var int Delivery address ID
* @deprecated
* @see setDeliveryAddress()
*/
public $fk_delivery_address;
@ -1623,7 +1624,8 @@ abstract class CommonObject
/**
* Define delivery address
*
* @deprecated
*
* @param int $id Address id
* @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)
* TODO Add a field into dictionary
* @deprecated
*
* @return boolean true = country inside EEC, false = country outside EEC
*/
function isInEEC()
{
// 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($this->country_code,$country_code_in_EEC);
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
return isInEEC($this);
}
@ -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
* Need $this->element & $this->id
@ -4711,4 +4661,61 @@ abstract class CommonObject
}
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);
}
}
/*
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 File

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

View File

@ -1,5 +1,5 @@
<?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) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -20,10 +20,9 @@
*/
/**
* \file dev/skeletons/skeleton_class.class.php
* \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
* Put some comments here
* \file modulebuilder/skeletons/skeleton_class.class.php
* \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
*/
// Put here all includes required by your class file
@ -34,26 +33,27 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
/**
* Class Skeleton_Class
*
* Put here description of your class
*
* @see CommonObject
* Put here description of your class.
*/
class Skeleton_Class extends CommonObject
{
/**
* @var string Id to identify managed objects
* @var string Id to identify managed object
*/
public $element = 'skeleton';
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'skeleton';
/**
* @var Skeleton_ClassLine[] Lines
*/
public $lines = array();
/**
* @var array Array with all fields and their property
*/
public $picto = 'generic';
/**
* @var array Array with all fields and their property
*/
public $fields;
/**
* @var mixed Sample property 1
*/
@ -62,8 +62,21 @@ class Skeleton_Class extends CommonObject
* @var mixed Sample property 2
*/
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
*
@ -289,10 +302,10 @@ class Skeleton_Class extends CommonObject
*/
public function update(User $user, $notrigger = false)
{
$error = 0;
dol_syslog(__METHOD__, LOG_DEBUG);
$error = 0;
// Clean parameters
if (isset($this->prop1)) {
$this->prop1 = trim($this->prop1);

View File

@ -1801,60 +1801,61 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->
/* Barre d'action */
/* */
/* ************************************************************************** */
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 ($action != 'create' && $action != 'edit')
{
if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer ) ||
($object->type == Product::TYPE_SERVICE && $user->rights->service->creer))
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 (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
if (! isset($object->no_button_copy) || $object->no_button_copy <> 1)
if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer ) ||
($object->type == Product::TYPE_SERVICE && $user->rights->service->creer))
{
if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))
if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
if (! isset($object->no_button_copy) || $object->no_button_copy <> 1)
{
print '<div class="inline-block divButAction"><span id="action-clone" class="butAction">'.$langs->trans('ToClone').'</span></div>'."\n";
}
else
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=clone&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a></div>';
if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))
{
print '<div class="inline-block divButAction"><span id="action-clone" class="butAction">'.$langs->trans('ToClone').'</span></div>'."\n";
}
else
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=clone&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a></div>';
}
}
}
}
$object_is_used = $object->isObjectUsed($object->id);
if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer)
|| ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer))
{
if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1))
$object_is_used = $object->isObjectUsed($object->id);
if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer)
|| ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer))
{
if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))
if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1))
{
print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))
{
print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
}
else
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("Delete").'</a></div>';
}
}
else
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("Delete").'</a></div>';
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ProductIsUsed").'">'.$langs->trans("Delete").'</a></div>';
}
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ProductIsUsed").'">'.$langs->trans("Delete").'</a></div>';
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a></div>';
}
}
else
{
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
*/
@ -1974,7 +1975,7 @@ if (! empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action =
* Documents generes
*/
if ($action != 'edit' && $action != 'delete')
if ($action != 'create' && $action != 'edit' && $action != 'delete')
{
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre

View File

@ -3326,18 +3326,6 @@ class Societe extends CommonObject
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
*

View File

@ -107,13 +107,14 @@ else if ($action == 'deletecontact' && $user->rights->societe->creer)
dol_print_error($db);
}
}
/*
else if ($action == 'setaddress' && $user->rights->societe->creer)
{
$object->fetch($id);
$result=$object->setDeliveryAddress($_POST['fk_address']);
if ($result < 0) dol_print_error($db,$object->error);
}
}*/
/*
* View